清除窗口所有内容的适当方法

  • 本文关键字:方法 窗口 清除 c# wpf
  • 更新时间 :
  • 英文 :


我正在寻找一种清除WPF中窗口全部内容的方法。到目前为止,我在网上找不到适合我需求的方法。但是我想出了这个:

假设我有MainWindow的观点,我正在做的是:

MainWindow.Content = null;
MainWindow.Content = new UserControl();

它确实有效,但我不确定这种方法是否安全和正确。

无需先将MainWindow.Content设置为null

您所要做的就是:

MainWindow.Content = new UserControl();

GC将负责其余的工作。

最新更新