我正在寻找一种清除WPF中窗口全部内容的方法。到目前为止,我在网上找不到适合我需求的方法。但是我想出了这个:
假设我有MainWindow
的观点,我正在做的是:
MainWindow.Content = null;
MainWindow.Content = new UserControl();
它确实有效,但我不确定这种方法是否安全和正确。
无需先将MainWindow.Content
设置为null
。
您所要做的就是:
MainWindow.Content = new UserControl();
GC将负责其余的工作。