Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I like using the Prism framework, however I feel that their Regions should only be used for Application Layout (<code>MenuRegion</code>, <code>NavigationRegion</code>, <code>ContentRegion</code>, 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.</p> <p>My preferred method for displaying changing content is with DataTemplates and ContentControls</p> <p>To create something like you outlined, I would have a parent ViewModel which contains</p> <ul> <li><code>ObservableCollection&lt;IPageViewModel&gt; PageViewModels</code></li> <li><code>IPageViewModel SelectedPageViewModel</code></li> </ul> <p>The area I wanted to display the dynamic content would use a ContentControl such as this:</p> <pre><code>&lt;ContentControl Content="{Binding SelectedPage" /&gt; </code></pre> <p>And DataTemplates would be used to tell WPF how to draw each section</p> <pre><code>&lt;DataTemplate TargetType="{x:Type local:Page1ViewModel}"&gt; &lt;local:Page1View /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate TargetType="{x:Type local:Page2ViewModel}"&gt; &lt;local:Page2View /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate TargetType="{x:Type local:Page3ViewModel}"&gt; &lt;local:Page3View /&gt; &lt;/DataTemplate&gt; </code></pre> <p>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:</p> <pre><code>&lt;Window&gt; &lt;Grid&gt; &lt;DockPanel&gt; &lt;RibbonBar ItemsSource="{Binding PageViewModels}" SelectedItem="{Binding SelectedPageViewModel}" DockPanel.Dock="Top" ...&gt; &lt;/RibbonBar&gt; &lt;StackPanel&gt; &lt;Grid&gt; ... Generic Content &lt;/Grid&gt; &lt;ContentControl Content="{Binding SelectedPageViewModel}"&gt; &lt;ContentControl.Resources&gt; &lt;DataTemplate TargetType="{x:Type local:Page1ViewModel}"&gt; &lt;local:Page1View /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate TargetType="{x:Type local:Page2ViewModel}"&gt; &lt;local:Page2View /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate TargetType="{x:Type local:Page3ViewModel}"&gt; &lt;local:Page3View /&gt; &lt;/DataTemplate&gt; &lt;/ContentControl.Resources&gt; &lt;/ContentControl&gt; &lt;/StackPanel&gt; &lt;/DockPanel&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload