我目前正在尝试修复一个bug,即在登录我的应用程序后加载window1(这很好),然后使用我创建的功能返回到登录表单以更改已登录用户,第二次加载Window1时出现错误。
错误信息为"指定的元素已经是另一个元素的逻辑子级。请先断开连接。"
window1代码如下:
public Window1()
{
InitializeComponent();
var tc = TabsControl.Instance as Control;
Grid.SetColumn(tc, 1);
Grid.SetRow(tc, 1);
//error happens on this line
grdMainContent.Children.Add(tc);
}
我不确定如何断开这个元素,并且在谷歌上一直没有成功。
我尝试过以下几件事情:
grdMainContent.Children.Remove(tc);
并且
if (!grdMainContent.Children.Contains(TabsControl.Instance as Control))
{
grdMainContent.Children.Add(tc);
}
并且
if (grdMainContent.Children.Contains(tc))
{
grdMainContent.Children.Add(tc);
}
非常感谢您一如既往的帮助。