2017-07-16 14 views
0

非常に単純な使用例:プロパティがNotifyPropertyChanged()の場合、Dictionary<string, string>に静的データとコンボボックスがあります。WPFコンボボックスの辞書へのバインド - 間違った値が返される

CBがそうのように定義されています。

<ComboBox ItemsSource="{Binding AllThings}" DisplayMemberPath="Value" 
SelectedValuePath="Key" SelectedItem="{Binding Thing, Mode=TwoWay, 
UpdateSourceTrigger=PropertyChanged}"> 

VMが含まれています

ユーザーは代わりに "B" 私は取得しています奇妙な文字列の値を選択
public Dictionary<string, string> AllThings { get; set; }= new Dictionary<string, string>{["a"] = "b"}; 

    private string thing; 

    public string Thing 
    { 
     get 
     { 
     return this.thing; 
     } 
     set 
     { 
     if (this.thing != value) 
     { 
      this.thing = value; 
      this.OnPropertyChanged(); 
     } 
     } 
    } 

Thingセッター内のvalue内の[a, b]

「b」を表示して「a」を「する」に保存したいとします。 bにはなりませんThingbに設定同様に

UPDは、リストで選択されています。

答えて

1

SelectedItemの代わりにSelectedValueを使用します。アイテムは、あなたが望むものではない辞書のキー/値のペアです。

+0

ありがとうございました。長い一日だった... – zaitsman

関連する問題