I am trying to set up user column control. I create each bar using a DataTemplate .
The problem is to calculate the height of each bar, first I need to know the height of its container ( TemplatedParent ). Unfortunately, I have:
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource HeightConverter}, Mode=OneWay}"
does not work. Every time the NaN value is returned to my converter. Does RelativeSource={RelativeSource TemplatedParent} not work in this context? What else can I do to let the DataTemplate "talk" to the element to which it applies?
In case this helps, these are the DataTemplate bytes:
<DataTemplate x:Key="BarGraphTemplate"> <Grid Width="30"> <Rectangle HorizontalAlignment="Center" Stroke="Black" Width="20" Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Height, Converter={StaticResource HeightConverter}, Mode=OneWay}" VerticalAlignment="Bottom" /> </Grid> </DataTemplate>
source share