[英]Move user control from main window to child window then back again to main window?
我有一個 MainWindow、一個 userControl 和一個 childWindow。 MainWindow 有一個擴展器,使用 MainWindowXaml.cs 中的以下代碼將其內容設置為 userControl 的實例:
public userControl
userControl1 = new userControl();
public MainWindow()
{
InitializeComponent();
expander.Content = userControl1;
}
然后我將 userControl1 在 childWindow 中單擊按鈕(該按鈕存在於擴展器的標題中):
private void b_click(...)
{
Window window = new Window();
window.Content = userControl1;
window.Closing += childWindow_closing;
window.Show();
expander.Visibility = Visibility.Collapsed;
}
有用。
現在我嘗試在 childWindow 關閉事件期間將 userControl1 放回擴展器:
private void childWindow_closing(...)
{
expander.Visibility = Visibility.Visible;
expander.Content = userControl1;
}
但是,這是行不通的。 childWindow 關閉並顯示擴展器。 但 userControl1 未顯示在擴展器中。 關於為什么的任何線索?
注意:上面提到的所有代碼都在 MainWindowXaml.cs 文件中。
正如@WSC 建議設置expander.Content = null; 解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.