简体   繁体   中英

WPF: One window, multiple views

Once I asked how to display multiple views in one window in a windows-forms-application ( link ). Now I'd like to know how to do the same in an WPF-application.

Your best option is to use an MVVM framework such as Caliburn.Micro , which makes view composition very easy. In this case, you would have your shell screen for example, which would be a conductor, and each of your sub screens would just be other view models, which your shell would have references to, and each would become the active item when they needed to be displayed.

You could have in your MainWindow.xaml, just one Stackpanel. Nothing else. You define all your views in other xaml files. Just that the parent element is not a Window. You need to have it as a Grid/StackPanel. When you want to load a new view, you just set the appropriate view's root element(or the view itself) as the Children of the StackPanel in MainWindow.xaml

I would recommend you to go to MVVM framework . I think you need a MainTabControl which will have child controls. The child controls are not needed to be Windows but UserControls. You can use DataTemplates in wpf to choose the view according to the viewmodel.

Please do let me know if you need more explanation on this.

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