Note that there are some explanatory texts on larger screens.

plurals
  1. POMVVM ListBox controlling a Content Control
    text
    copied!<p>I've been going round in circles with this for a couple of days, and I'm hoping a WPF guru can see where I'm going wrong. </p> <p>I'm setting CurrentViewModel in code. The Selected item of my ListBox and the Content of my ContentControl bind correctly. But when changing the selected item in the Listbox via the UI the CurrentViewModel is being set but the Content Control is not being updated.</p> <p>I'm using a data template to map my Views and View Models.</p> <pre><code> &lt;DataTemplate DataType="{x:Type ViewModel:MyViewModel}"&gt; &lt;View:MyView /&gt; &lt;/DataTemplate&gt; </code></pre> <p>I have a ListBox which is bound to an observable collection of ViewModels. The Selected Item is bound to the current view model.</p> <pre><code> &lt;ListBox ItemsSource="{Binding MyViewModelCollection}" DisplayMemberPath="DisplayName" SelectedItem="{Binding CurrentViewModel, Mode=TwoWay}"/&gt; </code></pre> <p>I also have a content control that is also bound to the CurrentView Model</p> <pre><code> &lt;ContentControl Content="{Binding CurrentViewModel, Mode=TwoWay}"/&gt; </code></pre> <p>This is the property that they are both bound to</p> <pre><code> public MyViewModel CurrentViewModel { get { return _currentViewModel; } set { if (_currentViewModel== value) return; _currentViewModel= value; OnPropertyChanged("CurrentViewModel"); } } </code></pre> <p>I've edited the names for clarity and removed formatting information.</p> <p>Any help greatly appreciated.</p> <p>Cheers,</p> <p>Daniel </p> <p>EDIT: Came across the link <a href="http://bea.stollnitz.com/blog/?p=52" rel="nofollow noreferrer" title="How can I debug WPF bindings?">How can I debug WPF bindings?</a>. I set a break point on the Content binding and it does indeed only get called once when the binding is first set.</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