Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: One window, multiple views

Tags:

c#

wpf

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.

like image 977
wullxz Avatar asked Nov 21 '11 21:11

wullxz


2 Answers

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

like image 103
gprasant Avatar answered Oct 17 '22 13:10

gprasant


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.

like image 27
devdigital Avatar answered Oct 17 '22 13:10

devdigital