I have a RibbonBar with four buttons, each of which selects a different view and injects it into the MainRegion. Right now, it’s working well but each of the four views have a few controls in common e.g. Displaying the username, date/time, search box etc. As of now, I’ve made separate views but I would like to know if there is a way of implementing a Master Page/UserControl so that I don’t have to repeat code.
So the design, right now, is like so:
Shell
<Window>
<Grid>
<DockPanel>
<RibbonBar Regions:RegionManager.RegionName="ToolbarRegion">
</RibbonBar>
<ContentControl Regions:RegionManager.RegionName="MainRegion">
</ContentControl>
</DockPanel>
</Grid>
</Window>
The ToolbarRegion contains the RibbonBar with the four buttons.
Each Button will inject a view into the MainRegion. Each of these views has some common controls (much like a Master Page in ASP.Net), but the content of each view is different.
There are ways to work around this (I can’t change the Shell design) but I was wondering if there was a better, more elegant way to do this.
I like using the Prism framework, however I feel that their Regions should only be used for Application Layout (
MenuRegion,NavigationRegion,ContentRegion, etc), and not Navigation. Using them for Navigation means letting the View control the application flow, and I feel that is a job for the ViewModels.My preferred method for displaying changing content is with DataTemplates and ContentControls
To create something like you outlined, I would have a parent ViewModel which contains
ObservableCollection<IPageViewModel> PageViewModelsIPageViewModel SelectedPageViewModelThe area I wanted to display the dynamic content would use a ContentControl such as this:
And DataTemplates would be used to tell WPF how to draw each section
I have not used a RibbonBar before, however it sounds like it should allow for an ItemsSource so your final XAML should probably look something similar to this: