I need edit Element property Schedule that selected in ListBox by ComboBox and after that by UserControl. ListBox and ComboBox and ContentControl are bound by CurrentElement in ModelView. To select item - selectedItem of ComboBox uses function Equals() of Types EveryDay or EveryMonth. This function compares pointers of Element.Schedule in ListBox and Schedule in ComboBox and them of course not equals. Behavior that I expect from ComboBox that objects of one class taken to be equivalent. I tried to use SelectedValue to compare unique value of type but this doesn't work correctly.
Thank for any suggestion.
I have MVVM master /details like this:
<Window.Resources>
<DataTemplate DataType="{x:Type model:EveryDay}">
<views:EveryDayView/>
</DataTemplate>
<DataTemplate DataType="{x:Type model:EveryMonth}">
<views:EveryMonthView/>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox Margin="12,24,0,35" Name="schedules"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Path=Elements}"
SelectedItem="{Binding Path=CurrentElement}"
DisplayMemberPath="Name" HorizontalAlignment="Left" Width="120"/>
<ContentControl Margin="168,86,32,35" Name="contentControl1"
Content="{Binding Path=CurrentElement.Schedule}" />
<ComboBox Height="23" Margin="188,24,51,0" Name="comboBox1" VerticalAlignment="Top"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Path=Schedules}"
SelectedItem="{Binding Path=CurrentElement.Schedule}"
DisplayMemberPath="Name"
SelectedValuePath="ID"
SelectedValue="{Binding Path=CurrentElement.Schedule.ID}"
/>
</Grid>
This Window has DataContext class:
public class MainViewModel : INotifyPropertyChanged
{
public MainViewModel()
{
_elements.Add(new Element("first", new EveryDay("First EveryDay object")));
_elements.Add(new Element("second", new EveryMonth("Every Month object")));
_elements.Add(new Element("third", new EveryDay("Second EveryDay object")));
_schedules.Add(new EveryDay());
_schedules.Add(new EveryMonth());
}
private ObservableCollection<ScheduleBase> _schedules = new ObservableCollection<ScheduleBase>();
public ObservableCollection<ScheduleBase> Schedules
{
get
{
return _schedules;
}
set
{
_schedules = value;
this.OnPropertyChanged("Schedules");
}
}
private Element _currentElement = null;
public Element CurrentElement
{
get
{
return this._currentElement;
}
set
{
this._currentElement = value;
this.OnPropertyChanged("CurrentElement");
}
}
private ObservableCollection<Element> _elements = new ObservableCollection<Element>();
public ObservableCollection<Element> Elements
{
get
{
return _elements;
}
set
{
_elements = value;
this.OnPropertyChanged("Elements");
}
}
One of the views:
<UserControl x:Class="Views.EveryDayView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid >
<GroupBox Header="Every Day Data" Name="groupBox1" VerticalAlignment="Top">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBox Name="textBox2" Text="{Binding Path=AnyDayData}" />
</Grid>
</GroupBox>
</Grid>

Recent comments
23 weeks 4 days ago