Hi
I am using Entity Framework in a project where ListBox is bound with ObservableCollection<tblYear> and SelectedItem is also bound with the property type of same Entity Object tblYear.
ViewModel:
private tblYear _SelectedYear; public tblYear SelectedYear { get { return _SelectedYear; } set { Set(ref _SelectedYear, value);} } ObservableCollection<tblYear> _Years; public ObservableCollection<tblYear> Years { get { return _Years; } set {Set(ref _Years, value);} }
View:
<ListBox ItemsSource="{Binding Years, Mode=OneWay}" SelectedItem="{Binding SelectedYear, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"><ListBox.ItemTemplate><DataTemplate><StackPanel Orientation="Horizontal"><TextBlock Padding="5,0,5,0" Text="{Binding Year}" /></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox>
In other ViewModel code part, when I set SelectedYear property to tblYear entity object, it is not getting updated on screen.
Same issue is explained at - ComboBox’s SelectedItem not Displaying but here suggested that we should set SelectedValue field which will return only PrimaryKey value to ViewModel. But I would like to have complete selected tblYear object in ViewModel.
In case of Entity Framework classes I am not able to understand the override implementation of ".Equals()".
Please suggest.