WPF
ComboBox
doesn't ever update text to
SelectedItem
's property, though
SelectedItem
changes on selection.
XAML:
<ComboBox Margin="4 0 2 0"
ItemsSource="{Binding XAxes}"
SelectedItem="{Binding SelectedXAxis, Mode=TwoWay}"
ItemTemplate="{StaticResource AxisCBTextTemplate}"/>
Template is:
<DataTemplate x:Key="AxisCBTextTemplate">
<TextBlock Text="{Binding AxisTitle}"/>
</DataTemplate>
VM:
private AxisCollection _xAxes;
public AxisCollection XAxes
{
get => _xAxes;
private set
{
_xAxes = value;
OnPropertyChanged("XAxes");
}
}
private IAxis _selectedXAxis;
public IAxis SelectedXAxis
{
get => _selectedXAxis;
set
{
_selectedXAxis = value;
OnPropertyChanged(nameof(SelectedXAxis));
}
}
SelectedXAxis
setter gets called, as well as
OnPropertyChanged
, but
ComboBox
does not show any text. List is shown as intended, no
AxisTitle
is lost.
What I have tried:
Changing
ItemTemplate
to
DisplayMemberPath
and
SelectedValuePath
:
<ComboBox Margin="4 0 2 0"
ItemsSource="{Binding YAxes}"
SelectedItem="{Binding SelectedYAxis, Mode=TwoWay}"
DisplayMemberPath="AxisTitle"
SelectedValuePath="AxisTitle"/>
Adding an
OnPropertyChanged("AxisTitle")
to a VM code;
Different combinations of ItemTemplate,
DisplayMemberPath
and
SelectedValuePath
;
Leaving only
<ComboBox Margin="4 0 2 0"
ItemsSource="{Binding YAxes}"/>
causes an exception.