i try to bind a wpf textbox to a dictionary placed in a viewmodel. The viewmodel is used as datacontext for the view. I found a lot of examples and it sounds simple, but it will not work for me.
View:
TextBox x:Name="txbTest" Grid.Row="10" Grid.Column="2" Text="{Binding MyDict[First]}"
ViewModel:
public Dictionary<string, string> MyDict = new Dictionary<string, string>
{
{"First", "Test1"},
{"Second", "Test2"}
};
I try all variants i found
Text="{Binding MyDict[First]}"
Text="{Binding Path=MyDict[First]}"
Text="{Binding MyDict[First].Text}"
Text="{Binding MyDict[First].Value}"
But nothing works, textbox is empty. Any idea?
MyDict
as a property. I have shared the sample code in my answer. – Anand Murali