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