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.
- And that one's in VB.NET while this one's in C#!BoltClock– BoltClock2011-11-21 22:00:05 +00:00Commented 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.wullxz– wullxz2011-11-21 22:03:48 +00:00Commented Nov 21, 2011 at 22:03
- It shouldn't; it was just something interesting I noticed :)BoltClock– BoltClock2011-11-21 22:07:07 +00:00Commented Nov 21, 2011 at 22:07
- Yeah, I'm trying to get into C# because I'll need it in a little while ;)wullxz– wullxz2011-11-21 22:09:17 +00:00Commented Nov 21, 2011 at 22:09
3 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
1 Comment
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
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.