我正在动态地绘制到我的 WPF 网格内的画布,但画布或网格都没有适当地拉伸。这是我的一些代码....
<Window x:Class="WPFNimGame.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Game of Nim" Height="auto" Width="auto" PreviewKeyDown="Window_PreviewKeyDown_1" Name="Window">
<Grid Name="Grid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="33"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border BorderBrush="Black" BorderThickness="10" Grid.RowSpan="2"/>
<!--<Grid.Background>-->
<!--<ImageBrush ImageSource=".\Properties\black-diamond-plate.bmp" -->
<!-- </Grid.Background>-->
<DockPanel VerticalAlignment="Top" Height="20" Width="{Binding ElementName=Window,Path=Width}" Grid.RowSpan="2" >
<Menu IsMainMenu="True" Margin="0" >
<MenuItem Name="File" Header="File" Click="File_Click_1">
<MenuItem Name="NewGame" Header="New Game" />
</MenuItem>
</Menu>
</DockPanel>
<Canvas Name="paintCanvas" Width="{Binding ElementName=Grid,Path=ActualWidth}" Height="{Binding ElementName=Grid,Path=ActualHeight}" MouseLeftButtonDown="paintCanvas_MouseLeftButtonDown" Grid.Row="1" >
<Border BorderBrush="Blue" BorderThickness="10" ></Border>
</Canvas>
</Grid>