My question is how to properly bind the properties of one element to another.
Here is the structure of my code:
The data template contains a grid (let it be called a GridA grid), and in the grid I specify an instance of a control called ControlA .
ControlA is a UserControl containing a Grid . In ControlA (code-behind), there is user logic that dynamically creates content, but in a nutshell uses a different data template.
The data template for ControlA consists of another Grid . I want to bind the Height property for this grid in this data template to the Height Grid property in the data template specified in my first mark above (a grid called GridA ).
Here is the XAML that I used to bind, but essentially it does not work as it does not find the Grid:
<Grid Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType=Grid, AncestorLevel=2}, UpdateSourceTrigger=PropertyChanged}"> </Grid>
I understand that by setting AncestorLevel=2 , it will use the second βfoundβ occurrence of the type you are looking for, in this case the Grid type. Therefore, in my opinion, he will first find the Grid in ControlA , then continue moving through the tree and find the Grid in the first data template, which is a Grid named GridA . This should be the second occurrence, right?
wpf binding
Chris
source share