質問

This is what I want:

  • There is a combo-box column bound to the ApplicationKey property of ClassA
  • The combo-box is populated with ApplicationTokens from a static function all.
  • An ApplicationToken has a ApplicationName and ApplicationKey property
  • When an item is selected in the drop-down, the ClassA.ApplicationKey property is set to the ApplicationToken.ApplicationKey on the selected item.

This is my current code, which populates the combobox but doesn't update ClassA.ApplicationKey.

<DataGridComboBoxColumn 
    Header="Application" 
    SelectedItemBinding="{Binding ApplicationKey, Converter={gui:DebugConverter}}" 
    SelectedValuePath="ApplicationKey" 
    DisplayMemberPath="ApplicationName" 
    ItemsSource="{Binding Source={x:Static app:ApplicationLookup.GetAllOrNone}}"/>
役に立ちましたか?

解決

Use SelectedValueBinding instead of SelectedItemBinding when using SelectedValuePath.

Working example

<DataGridComboBoxColumn 
    Header="Application" 
    SelectedValueBinding="{Binding ApplicationKey}"
    SelectedValuePath="ApplicationKey" 
    DisplayMemberPath="ApplicationName" 
    ItemsSource="{Binding Source={x:Static app:ApplicationLookup.GetAllOrNone}}"/>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top