Note that there are some explanatory texts on larger screens.

plurals
  1. POCombobox SelectedItem doesn't update when source changes
    text
    copied!<p>I have a viewmodel which implement <code>INotifyPropertyChanged</code>. On this viewModel is a property called <code>SubGroupingView</code>. This property is bound to the selected item of a combo box. When i change the combo box, the source property is being updated fine, but when I change the source property or when the control is initialized, the <code>combobox.selectedItem</code> is NOT reflecting what exists in the property.<br> Here is some code to get you started: </p> <pre><code>&lt;ComboBox Grid.Column="3" Grid.Row="1" Margin="0,1,4,1" SelectedItem="{Binding Path=SubGroupingView, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, diag:PresentationTraceSources.TraceLevel=High}" ItemsSource="{Binding Columns}" DisplayMemberPath="DisplayName"&gt; </code></pre> <p>The property raises the <code>PropertyChanged</code> event and the TraceSource output shows me that the binding detected it and transferred the value, its just that the combobox isn't reflecting it. Any ideas would be most welcome!</p> <p>EDIT:<br> output from the trace source is this: </p> <pre><code>System.Windows.Data Warning: 91 : BindingExpression (hash=23631369): Got PropertyChanged event from ReportViewModel (hash=52844413) System.Windows.Data Warning: 97 : BindingExpression (hash=23631369): GetValue at level 0 from ReportViewModel (hash=52844413) using RuntimePropertyInfo(SubGroupingView): DataColumnViewModel (hash=58231222) System.Windows.Data Warning: 76 : BindingExpression (hash=23631369): TransferValue - got raw value DataColumnViewModel (hash=58231222) System.Windows.Data Warning: 80 : BindingExpression (hash=23631369): TransferValue - implicit converter produced DataColumnViewModel (hash=58231222) System.Windows.Data Warning: 85 : BindingExpression (hash=23631369): TransferValue - using final value DataColumnViewModel (hash=58231222) </code></pre> <p>Here is the code for the source property:</p> <pre><code>public class ReportViewModel : ViewModelBase, IReportTemplate { public DataColumnViewModel SubGroupingView { get { return GetViewModel(_report.SubGrouping); } set { if (_report.SubGrouping == value.ColumnName) return; _report.SubGrouping = value.ColumnName; RefreshDataSeries(); base.OnPropertyChanged("SubGroupingView"); base.OnPropertyChanged("IsReady"); } } } </code></pre> <p>Note: <code>ViewModelBase</code> implements <code>INotifyPropertyChange</code>.</p> <p><strong>ANSWER</strong><br> I overloaded the ==, != operators, <code>GetHashCode()</code>, and <code>Equals(object)</code> and now it is working nicely. Thanks for all of your help!</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