如何在應用轉換後確定控件的實際寬度和實際高度?如何在應用ScaleTransform後確定控件大小?
例如,我認爲下面的XAML代碼應顯示大小類似400×400(例如,在照片。紅色長方形,其寬度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>
這裏有什麼實際的目標是什麼?你需要什麼信息? –
@EdPlunkett在正確的控件安排在我的控制任何轉換後。 – slavka