3
我目前正在嘗試修復一個在登錄到我的應用程序(工作正常)後加載我的window1的bug,然後我使用我創建的功能返回到登錄表單來更改登錄用戶,並且第二次加載我的Window1時出現錯誤「指定的元素已經是另一個元素的邏輯子元素,先斷開它連接」第二次調用窗口時出錯
錯誤消息 「指定的元素已經是另一個元素的邏輯子元素。首先斷開它。「
窗口1碼是
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);
}
不知道如何切斷這個元素,並SOFAR一直對谷歌不成功。
我試過的是以下的東西。
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);
}
任何幫助是一如既往不勝感激
由於多數民衆贊成按預期工作:) –