我想通过使用 DataTrigger 将 ComboBox 的 SelectedIndex 设置为 0,当它绑定的 SelectedItem 为空时。但它不起作用。我哪里错了?
xml如下:
<ComboBox SelectedItem="{Binding MyObject.color_master, Mode=TwoWay}"
ItemsSource="{Binding MyEntities.color_master}"
DislayMemberPath="COLOR_DESCRIPTION" >
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=MyObject.color_master}" Value="{x:Null}">
<Setter Property="SelectedIndex" Value="0" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
这里MyObject.color_master为空,但 DataTrigger 仍然无法正常工作!
我的要求很简单,当组合框中没有选择任何内容时,我希望选择第一项。