绑定DataGridComboBoxColumn SelectedIndex

时间:2013-01-22 19:01:42

标签: c# wpf datagrid

我知道之前有人问过这件事。我正在检查是否有任何新的聪明解决方案。有没有更好的方法来绑定SelectedIndex的{​​{1}}?这就是我在谷歌搜索后得到绑定的方式:

DataGridComboBoxColumn

1 个答案:

答案 0 :(得分:1)

这是绑定DataGridComboBoxColumn的SelectedIndex,ItemSource,IsReadOnly的最佳答案。

<DataGridComboBoxColumn Header="Batch Type"
  ItemsSource="{Binding Source={StaticResource methodOfPaymentItemsProvider}}">

  <DataGridComboBoxColumn.ElementStyle>
    <Style TargetType="ComboBox">
        <Setter Property="SelectedIndex" Value="{Binding MethodOfPayment,  UpdateSourceTrigger=PropertyChanged}" />
        <Setter Property="ItemsSource" Value="{Binding Streets, RelativeSource= {RelativeSource FindAncestor,AncestorType=UserControl}, Mode=OneWay}"/>
        <Setter Property="IsReadOnly" Value="True"/>
    </Style>
 </DataGridComboBoxColumn.ElementStyle>
 <DataGridComboBoxColumn.EditingElementStyle>
    <Style TargetType="ComboBox">
        <Setter Property="SelectedIndex" Value="{Binding MethodOfPayment, UpdateSourceTrigger=PropertyChanged}" />
        <Setter Property="ItemsSource" Value="{Binding Streets, RelativeSource={RelativeSource FindAncestor,AncestorType=UserControl}, Mode=OneWay}"/>
     </Style>
 </DataGridComboBoxColumn.EditingElementStyle>
 </DataGridComboBoxColumn>