に望むように、あなたは必ず、あなたのことをする必要がViewModel KeyCollectionと辞書の両方を保持します。ここに私の解釈:
は、あなたがこのビューモデルがあるとします。
public class DictVm
{
public Dictionary<string, string> MainDictionary { get; set; }
public ObservableCollection<string> MyKeyCollection{ get; set; }
public string SelectedKey{ get; set; }
private string _selectedDictValue;
public string SelectedDictValue {
get {
if (MainDictionary.TryGetValue(SelectedKey, _selectedDictValue))
return _selectedDictValue;
return string.Empty;
}
set { _selectedDictValue = value; } }
}
ここでは、あなたのメイン・ウィンドウコンストラクタは次のとおりです。
private DictVm vm;
public MainWindow()
{
InitializeComponent();
vm = new DictVm();
DataContext = vm;
}
私はXAMLを変更する方法をここで
:
<ComboBox x:Name="MyCombo" ItemsSource="{Binding MyKeyCollection}" SelectedValue="{Binding SelectedKey}"/>
<TextBox Text="{Binding SelectedDictValue}"/>