Binding DataGridComboBoxColumn SelectedIndex

I know this was asked before. I check if there are new smart solutions. Is there a better way to bind SelectedIndex to a DataGridComboBoxColumn ? Here's how I got a snap to working after a big googling:

 <!-- This is a little ridiculous --> <DataGridComboBoxColumn Header="Batch Type" ItemsSource="{Binding Source={StaticResource methodOfPaymentItemsProvider}}"> <DataGridComboBoxColumn.ElementStyle> <Style TargetType="ComboBox"> <Setter Property="SelectedIndex" Value="{Binding MethodOfPayment, UpdateSourceTrigger=PropertyChanged}" /> </Style> </DataGridComboBoxColumn.ElementStyle> <DataGridComboBoxColumn.EditingElementStyle> <Style TargetType="ComboBox"> <Setter Property="SelectedIndex" Value="{Binding MethodOfPayment, UpdateSourceTrigger=PropertyChanged}" /> </Style> </DataGridComboBoxColumn.EditingElementStyle> </DataGridComboBoxColumn> 
+4
source share
1 answer

This is the best answer for binding SelectedIndex, ItemSource, IsReadOnly to DataGridComboBoxColumn.

 <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> 
+1
source

All Articles