Reputation:
I have a Public Dictionary defined as
public Dictionary<string, double> comboBoxSelections { get; set; }
and add items to it using
this.comboBoxSelections = new Dictionary<string, double>();
comboBoxSelections.Add(currItem, d);
I want to use this as an ItemsSource for a ComboBox in WPF so whenever comboBoxSelections is updated I see the updated items available for selection in the ComboBox. So I think perhaps I need to wrap this in an ObservableCollection as
public ObservableCollection<Dictionary<string, double>> comboBoxSelections { get; set; }
this.comboBoxSelections = new ObservableCollection<Dictionary<string, double>>();
What is the syntax for adding new Dictionary items to the ObservableCollection? Something like...
comboBoxSelections.Add(new Dictionary<string, double>(currItem, d));
Upvotes: 0
Views: 933
Reputation: 2383
You can use ObservableCollection<KeyValuePair<string,double>>
or ObservableCollection<Tuple<string,double>>
then you can bind to these values in XAML.
Or you can use ObservableDictionary check here and there.
Upvotes: 3