Consider the following XAML:
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <StackPanel> <TextBlock Text="{Binding Dic[foo]}" /> <Button Content="test" Click="Button_Click" /> </StackPanel> </Window>
And Code:
namespace WpfApplication1 { public partial class MainWindow : Window { public Dictionary<string, string> Dic { get; set; } public MainWindow() { InitializeComponent(); Dic = new Dictionary<string, string>(); Dic.Add("foo", "bar"); DataContext = this; } private void Button_Click(object sender, RoutedEventArgs e) {
Here, the TextBlock correctly bound to the dictionary element "foo". But how to make it update when its value changes?
source share