views:

34

answers:

1

I have the following XAML:

<Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource MyDataKey}}">
 <TextBox Name="_myId" Text="{Binding MyDictionary[(Textbox.Name)]}" />
</Grid>

But it thinks the key in my dictionary is called "(Textbox.Name)", instead of "_myId". The format below works, where I have a property in my class called "_myId":

<TextBox Name="_myId" Text="{Binding (Textbox.Name)}" />

I've tried using ^ and \ to escape the brackets. Is this syntax supported? I'm trying to avoid duplication of the name in two attributes.

+2  A: 

You can not have references to other instances in indexers in XAML binding expressions. You can only have acutal literals such as Text="{Binding MyDictionary[somename]"}, wich is the c# equivalent to myDictionary["somename"].

bitbonk
Looks like I'll have to stick `"_myId"` twice in the attribute declaration which is a bit annoying
Chris S