Hi all,
I have a viewmodel which implement INotifyPropertyChanged. On this viewModel is a property called SubGroupingView. 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 combobox.selectedItem is NOT reflecting what exists in the property.
Here is some code to get you started:
<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">
The property raises the PropertyChanged 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!
EDIT:
output from the trace source is this:
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)
Here is the code for the source property
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");
}
}
}
Note: ViewModelBase implements INotifyPropertyChange
ANSWER
I overloaded the ==, != operators, GetHashCode(), and Equals(object) and now it is working nicely. Thanks for all of your help!