在UserControl中更改Window.Content值

时间:2012-08-21 19:03:18

标签: wpf user-controls

我有一个窗口和一些userControls。当Window加载时,UserControls之一以programicaly托管在Window.Content中。假设,userControls具有按钮,当用户点击此按钮时,将当前UserControl从window.Content和destoryed以及另一个userControl添加到父Window.Content中。我像这样使用Parent:

(Parent as Window).Content =  new MyUserControl;

但是一旦更改了父userControl,Parent返回null的结果和之前的userConrol没有被破坏。

1 个答案:

答案 0 :(得分:0)

刚刚创建了附加的示例来测试您要执行的操作。请提供有关您所拥有代码的更多详细信息。附加的样本完全按照你的说法进行,没有任何空引用。

Sample