我正在动画到我的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>
答案 0 :(得分:1)
<Grid Name="gridMain" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinition>
</Grid>
答案 1 :(得分:0)
如果Grid
的宽度或高度等于“NaN”,则将根据其Children
的大小确定它们。问题是您已将Children
的大小设置为与网格大小相同。这将不起作用,结果将始终为0.
儿童的大小取决于他们的内容或儿童。如果您希望它们具有确定的大小,则将“高度”和“宽度”设置为等于特定的双倍。