I'm trying to data bind a TextBlock to the RenderSize of a Rectangle. Here is the code.
<StackPanel x:Name="root">
<Rectangle x:Name="rect" Fill="Green" RenderTransformOrigin="0.5,0.5" Height="100" Width="100" />
<TextBlock Text="{Binding ElementName=rect, Path=Width}"></TextBlock>
<TextBlock Text="{Binding ElementName=rect, Path=ActualWidth}"></TextBlock>
<TextBlock Text="{Binding ElementName=rect, Path=RenderSize}"></TextBlock>
<Slider Value="{Binding ElementName=rect, Path=Width, Mode=TwoWay}" Maximum="200"></Slider>
<Button Content="Manually Get RenderSize" Click="Button_Click_1"></Button>
<TextBlock x:Name="info"></TextBlock>
</StackPanel>
When I move the slider, rect become larger, and the first TextBox is updated correctly. However, ActualWidth and RenderSize stay to 0, and 0,0.
When I click on Button, I get the RenderSize programmatically and show it in the last TextBlock, which is different than 0,0.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
info.Text = rect.RenderSize.ToString();
}
So my binding on the RenderSize does not update the TextBox correctly... Why ? Thanks for your help,