简体   繁体   English

“清除”窗口为新用户控件腾出空间?

[英]“Clear” window to make room for new user controls?

I'm usually working with Windows Forms Applications, but I'm currently needing Windows Presentation Foundation for design purposes. 我通常使用Windows Forms Applications,但我目前需要Windows Presentation Foundation来进行设计。

What I am needing to do is clear out the current open window and fill it with new user controls as though a new window has been opened. 我需要做的是清除当前打开的窗口并用新用户控件填充它,就好像打开了一个新窗口一样。 In short, open a new window without actually opening a new window, similar to navigating to a new page in a web browser. 简而言之,打开一个新窗口而不实际打开一个新窗口,类似于在Web浏览器中导航到新页面。 (Still the same window open in the Taskbar, no extras.) (在任务栏中打开相同的窗口,没有额外的。)

I was unsure if there was a specific class or control that made this easy to do. 我不确定是否有一个特定的类或控件使这很容易做到。 If someone could enlighten me on the way to do this in WPF, I would be very pleased. 如果有人可以在WPF的方式上启发我,我会非常高兴。

Thanks. 谢谢。

There are a number of possible ways - here are a few that come to mind: 有许多可能的方法 - 以下是一些想到的方法:

Navigation 导航

In WPF, you can actually navigate to different xaml pages. 在WPF中,您实际上可以导航到不同的xaml页面。 In this scenario, you would define a number of pages that a main page could navigate to. 在这种情况下,您将定义主页可以导航到的页面数。

http://msdn.microsoft.com/en-us/library/ms750478.aspx http://msdn.microsoft.com/en-us/library/ms750478.aspx

Programmatic 编程

You can do it the old school way and just clear out all of the controls in a window. 你可以用旧学校的方式做,只需清除窗口中的所有控件。 For example (in the context of a window): 例如(在窗口的上下文中):

StackPanel stackPanel = new StackPanel();

stackPanel.Children.Add(new MyUserControl1());
stackPanel.Children.Add(new MyUserControl2());

this.Content = stackPanel;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM