Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you should be looking at the <code>VisualTree</code> for the Content, not your <code>LogicalTree</code>. </p> <p>Also, I couldn't really tell from your question above, but it sounded like you might be looking your ContentTemplate for your Content. If that is the case, it won't work because it's a template, so it doesn't actually contain the content. It's like looking at the Cookie Cutter to find the Cookie.</p> <p>And as a side note, I prefer to use DataTemplates than DataTriggers. You don't need a DataTemplateSelector either</p> <p>In my ParentViewModel I'll have a property like this:</p> <pre><code>private ViewModelBase _currentContent; public ViewModelBase CurrentContent { get {return _currentContent;} set { if (value != _currentContent) { _currentContent = value; OnPropertyChanged("CurrentContent"); } } } </code></pre> <p>and in the XAML for the ParentViewModel I would have something like</p> <pre><code>&lt;ContentControl Content="{Binding CurrentContent}" /&gt; </code></pre> <p>Then I'd define my data templates for the different sub-viewmodel types</p> <pre><code>&lt;DataTemplate DataType="{x:Type local:SubViewModelA}"&gt; &lt;local:ViewA /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type local:SubViewModelB}" /&gt; &lt;local:ViewB /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type local:SubViewModelC}" /&gt; &lt;local:ViewC /&gt; &lt;/DataTemplate&gt; </code></pre> <p>To switch content, I'd change the master's <code>CurrentContent</code> property to whatever SubViewModel should be displayed</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