0

我正在动态地绘制到我的 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>

4

2 回答 2

1

请检查答案尝试设置行高*

<Grid Name="gridMain" > 
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinition>
</Grid>
于 2014-11-19T07:34:18.653 回答
0

如果宽度或高度 aGrid等于“NaN”,它们将根据其大小确定Children。问题是您已将大小设置Children为与网格大小相同。这将不起作用,结果将始终为 0。

子项的大小取决于其内容或子项。如果您希望它们具有确定的大小,则将高度和宽度设置为等于特定的双精度值。

于 2012-12-09T08:05:49.237 回答