2013-01-22 137 views
4

我知道這已被問過。我正在檢查是否有任何新的聰明解決方案。有沒有更好的方法來綁定DataGridComboBoxColumnSelectedIndex?這是我得到了結合後多谷歌搜索工作:綁定DataGridComboBoxColumn SelectedIndex

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

而你的問題是? – Botonomous

回答

1

這是綁定的SelectedIndex,的ItemSource,一個DataGridComboBoxColumn的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> 
相關問題