wullxz
wullxz

Reputation: 19420

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.

Upvotes: 7

Views: 12296

Answers (3)

gprasant
gprasant

Reputation: 16023

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

Upvotes: 2

Coder323
Coder323

Reputation: 580

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.

Upvotes: 0

devdigital
devdigital

Reputation: 34349

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.

Upvotes: 1

Related Questions