hello我有以下問題:我想用方法Canvas.SetLeft()和Canvas.SetTop()在畫布上繪製一個矩形。當更改網格的寬度時更新矩形的寬度
我使用的方法UserControl_Loaded()和一切正常。 問題是,在調整窗口大小並因此改變網格的大小時,ActualWidth值不會改變,而且我的值不再準確。
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Rectangle rett = new Rectangle();
rett.Height = grid1.ActualHeight-10;
rett.Width = grid1.ActualWidth -10;
rett.Fill = new SolidColorBrush(Colors.LightBlue);
canv.Children.Add(rett);
Canvas.SetLeft(rett, 10);
Canvas.SetTop(rett, 10);
}
這是XAML:
<Grid x:Name="grid1">
<Canvas x:Name="canv" Height="auto" Width="auto"></Canvas>
</Grid>
中的第一張照片是罰款時,不調整窗口的大小。
第二時我調整網格保持先前的寬度。
我想改變格柵的寬度時,矩形的寬度進行了更新。 謝謝。