2017-02-28 5 views
0

コンボボックスを設定するためにISO国コードとその説明をリストしたエンティティテーブルがあります。次に、「国籍」をComboBoxの選択した値に設定する別のテーブルがあります。私はIsoCountryCodesと私の他のテーブルの間に外来キーの制約はありません。ItemsSourceの選択項目/テキストから値のパスへのコンボボックスの設定

ComboBoxのSelectedItemを選択したIsoCountryCodeに設定できますが、SelectedValueを '国籍'フィールドに保存します。

ComboBoxのSelectedItemを '国籍'(文字列)フィールドに設定しようとしましたが、IsoCountryCodeでToString()を実行しています。 SelectedItemの代わりに 'Text'フィールドを設定すると、DisplayPathの値が 'nationality'フィールドに保存されます。

ユーザーに有効なDisplayPathを表示している間に、外部キー制約なしでフィールドに保存するValuePath値を取得する方法があるのでしょうか? USAへ

<xctk:WatermarkComboBox x:Name="uxNationalityCmbo" Margin="0,0,5,5" Watermark="Nationality" 
     Grid.Row="2" ItemsSource="{Binding CountryCodeCollection}" SelectedValuePath="IsoCode" DisplayMemberPath="IsoDescription" 
     IsTextSearchEnabled="True" Text="{Binding SelectedPassenger.PassengerNationality, TargetNullValue=''}"/> 

今選択した値を変更しますでしょう:

IsoCountryCodeテーブルの例:

IsoCode  IsoDescription 

'GBR'  'United Kingdom' 
'USA'  'United States of America' 

他のテーブルの例:

PassengerId PassengerName PassengerNationality PassengerDocumentIssuingCountry 
1   'Carter, John' 'GBR'    'USA' 

そして、私の現在のXAMLは、エンティティPassengerNationalityを 'United States of America'に変更しますが、 'USA'が必要です

答えて

1

あなたはPassengerNationalityソースプロパティにSelectedValueプロパティをバインドする必要があります。

<xctk:WatermarkComboBox x:Name="uxNationalityCmbo" Margin="0,0,5,5" Watermark="Nationality" 
    Grid.Row="2" ItemsSource="{Binding CountryCodeCollection}" SelectedValuePath="IsoCode" DisplayMemberPath="IsoDescription" 
    IsTextSearchEnabled="True" SelectedValue="{Binding SelectedPassenger.PassengerNationality, TargetNullValue=''}"/> 
関連する問題