如何在应用变换后确定控件的实际宽度和实际高度?
例如,我认为以下XAML代码应该显示像400x400这样的大小(例如,在图片中,红色矩形的宽度为400),但是宽度和高度都等于200。
我做错了什么?
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="VisualCad.Components.TempVisualTests.MainWindow"
mc:Ignorable="d"
x:Name="MyWin"
Title="MainWindow" WindowState="Maximized" Height="500" Width="500">
<Grid>
<Rectangle Width="400" Height="5" Fill="Red" Margin="0,20,0,0" VerticalAlignment="Top"/>
<Canvas x:Name="MyCanvas" Width="200" Height="200">
<Canvas.RenderTransform>
<ScaleTransform CenterX="100" CenterY="100" ScaleX="2" ScaleY="2" />
</Canvas.RenderTransform>
<StackPanel>
<TextBlock Text="{Binding Path=RenderSize, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Canvas}}, StringFormat='Render size: {0}'}" />
<TextBlock Text="{Binding Path=ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Canvas}}, StringFormat='ActualWidth: {0}'}" />
<TextBlock Text="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Canvas}}, StringFormat='ActualHeight: {0}'}" />
</StackPanel>
</Canvas>
</Grid>
</Window>