简体   繁体   中英

“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.

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. (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.

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. 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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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