我正在使用DataGrid绑定到DataTable。
我想要做以下事情: 如果TargetUnit列的值为空,则将Combobox的SelectedIndex更改为1 否则将SelectedIndex更改为0.
我正在做以下事情:
<DataGrid MaxHeight="400" Height="Auto" Width="Auto" IsEnabled="{Binding Enabled}" ItemsSource="{Binding Spread.DefaultView}" SelectedItem="{Binding SpreadSelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Header="Value" Binding="{Binding Path=Value}" Width="70"/>
<DataGridTextColumn IsReadOnly="True" Header="No of Items" Binding="{Binding Path=NoOfItems}" />
<DataGridTextColumn Header="Rename Unit" Binding="{Binding Path=TargetUnit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<DataGridComboBoxColumn Header="Action Type" SelectedItemBinding="{Binding Path=ActionType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource SpreadActionTypeConverter}}">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.UnitConversionActionTypes}"/>
<Setter Property="SelectedIndex" Value="0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}, Path=TargetUnit}" Value="">
<Setter Property="SelectedIndex" Value="1"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.UnitConversionActionTypes}"/>
<Setter Property="SelectedIndex" Value="0"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}, Path=TargetUnit}" Value="">
<Setter Property="SelectedIndex" Value="1"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>
知道如何实现这一目标吗?