I don't think you're going to be able to do what you'd like with a dictionary.
- Because the Dictionary doesn't implement INotifyPropertyChanged or INotifyCollectionChanged
- Because it's not going to allow two way binding like you want.
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<int>
Custom Class
public class MyCustomClass
{
public string Key { get; set; }
public int Value { get; set; }
}
Set ItemsSource
ObservableCollection<MyCustomClass> dict = new ObservableCollection<MyCustomClass>();
dict.Add(new MyCustomClass{Key = "test", Value = 1});
dict.Add(new MyCustomClass{ Key = "test2", Value = 2 });
listView.ItemsSource = dict;
XAML
<Window.Resources>
<DataTemplate x:Key="ValueTemplate">
<TextBox Text="{Binding Value}" />
</DataTemplate>
</Window.Resources>
<ListView Name="listView">
<ListView.View>
<GridView>
<GridViewColumn CellTemplate="{StaticResource ValueTemplate}"/>
</GridView>
</ListView.View>
</ListView>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…