Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't need all that ScreenManager stuff in WPF, because the DataTemplate engine can take care of this for you with pure markup.</p> <p>You can simply databind a particular area of your application with a ContentPresenter and a bunch of DataTemplates. Bind the area to a property of a 'root' ViewModel, and let the 'root' ViewModel implement INotifyPropertyChanged so that WPF knows if you change the ViewModel in that area.</p> <pre><code>public class RootViewModel : INotifyPropertyChanged { public object Screen1ViewModel { get; } public object Screen2ViewModel { get; } } </code></pre> <p>Databind one ContentPresenter control to the Screen1ViewModel property using</p> <pre><code>&lt;ContentControl Content="{Binding Path=Screen1ViewModel}" /&gt; </code></pre> <p>and similarly for the next one. When you need to change the content of Screen1, you simply re-assign Screen1ViewModel from code, and because of the raised PropertyChanged event, WPF will pick it up and bind the new ViewModel to a new View.</p> <p>The DataTemplates may be as simple as this:</p> <pre><code>&lt;Window.Resources&gt; &lt;DataTemplate DataType="{x:Type foo:MyViewModel}"&gt; &lt;self:MyControl /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type foo:MyOtherViewModel}"&gt; &lt;self:MyOtherControl /&gt; &lt;/DataTemplate&gt; &lt;/Window.Resources&gt; </code></pre> <p>In case you are not familiar with it, <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="nofollow noreferrer">this article on MVVM in WPF</a> is an excellent introduction.</p>
 

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