WPF: single window, multiple views

As soon as I asked how to display multiple views in one window in windows-forms-application () application. Now I would like to know how to do the same in a WPF application.

+4
source share
3 answers

You can have in your MainWindow.xaml only one Stackpanel. Nothing more. You define all your views in other xaml files. It’s just that the parent is not a window. You must have it as a Grid / StackPanel. When you want to load a new view, you simply set the corresponding root element of the view (or the view itself) as children of the StackPanel in MainWindow.xaml

+1
source

Your best bet is to use an MVVM environment such as Caliburn.Micro , which makes browsing a song very easy. In this case, for example, you will have a shell screen that will be a conductor, and each of your sub-screens will simply be different view models to which your shell will have links, and each of them will become an active element when they are needed for display.

0
source

I would recommend you switch to the MVVM framework . I think you need a MainTabControl that will have child controls. Children's controls do not require Windows, but UserControls. You can use DataTemplates in wpf to select a view according to the viewing model.

Please let me know if you need more explanation.

0
source

Source: https://habr.com/ru/post/1382384/


All Articles