I have a static Dictionary
class X { static Dictionary<string,string> MyDict {get { ... }} }
This Dictionary contains Data i want to show in a Grid-Control:
<Grid>
<!-- Row and Column-Definitions here -->
<Label Grid.Row="0" Grid.Column="0" Content="{Binding MyDict.Key=="foo" }" ToolTip="foo" />
<!-- some more labels -->
</Grid>
1.) i dont know how to get access (in xaml) to the dictionary
2.) i want to bind the Value of a specified key to the Content-Property of the Label.
how to do this?
To get access to the Dictionary, you have to do something like this (if your DataContext isn't already an instance of X
):
<Grid>
<Grid.DataContext>
<X xmlns="clr-namespace:Your.Namespace" />
</Grid.DataContext>
<!-- other code here -->
</Grid>
To access the values in the dictionary, your binding has to look as follows:
<Label Content="{Binding MyDict[key]}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With