Reputation: 1051
Suppose I have two elements. Lets say,
Now If I want to bind Text of TextBox to the Text of TextBlock I can do something like :
<TextBox Text="{Binding Text, ElementName=someTextBlock}" />
Now if my TextBlock is inside a Grid as follows:
<Grid>
<TextBlock Text="someText" Grid.Row=1 Grid.Column=2 />
</Grid>
Now my question is how to bind Text of the TextBox to Grid.Row or Grid.Column?
I mean
<TextBox Text={Binding Grid.Row, ElementName=someTextBlock} />
The above code does not work.
I know I am doing something wrong here.
Upvotes: 1
Views: 690
Reputation: 564373
You need to use this syntax:
<TextBox Text={Binding Path=(Grid.Row), ElementName=someTextBlock} />
This is documented in Binding.Path:
To bind to an attached property, place parentheses around the attached property. For example, to bind to the attached property DockPanel.Dock, the syntax is Path=(DockPanel.Dock).
For example, this displays 2 rows, with a TextBox
containing "1" and a TextBlock
below:
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Text="{Binding Path=(Grid.Row), ElementName=someTextBlock}"></TextBox>
<TextBlock Grid.Row="1" Name="someTextBlock" Text="Foo" />
</Grid>
Upvotes: 5