7

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.

4
  • And that one's in VB.NET while this one's in C#! Commented Nov 21, 2011 at 22:00
  • That shouldn't make any difference since, right? (since WPF is the technique to design the user-interface in XAML and it's available for all .Net-languages) If there's something to code, I'd also be satisfied with VB .Net-Code. I'll convert the code to C# then. Commented Nov 21, 2011 at 22:03
  • It shouldn't; it was just something interesting I noticed :) Commented Nov 21, 2011 at 22:07
  • Yeah, I'm trying to get into C# because I'll need it in a little while ;) Commented Nov 21, 2011 at 22:09

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

can you give me an example how to change the displayed view in my code?
1

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.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.