I\'d like to bind a Dictionary
to a ListView
in WPF. I\'d like to do this in such a way that the Values
in the
I don't think you're going to be able to do what you'd like with a dictionary.
I'm not sure if it fits your requirements exactly, but I would use an ObservableCollection
, and a custom class.
I'm using a DataTemplate, to show how to make the binding on the values two way.
Of course in this implementation Key isn't used, so you could just use an ObservableCollection
Custom Class
public class MyCustomClass
{
public string Key { get; set; }
public int Value { get; set; }
}
Set ItemsSource
ObservableCollection dict = new ObservableCollection();
dict.Add(new MyCustomClass{Key = "test", Value = 1});
dict.Add(new MyCustomClass{ Key = "test2", Value = 2 });
listView.ItemsSource = dict;
XAML