0
我正在開發一個應用程序使用WPF c#。我爲窗口設置了Width = 700和Height = 700,我的窗口有一個嵌套的Grid,Border和Canvas。 Horizonta和邊界和帆布的垂直對齊是拉伸。預計「實際寬度」和「畫布實際高度」爲700,但它們爲682和659。出錯了?我錯過了設置一些屬性嗎?水平和垂直在帆布彈力
我用這個xaml
代碼:
<Window x:Class="proj.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="700" Width="700" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded">
<Grid>
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Canvas x:Name="cnv" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
</Canvas>
</Border>
</Grid>
</Window>
這裏是「Window_Loaded」事件代碼:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show(cnv.ActualWidth + "\n" + cnv.ActualHeight);
}