首页 > 解决方案 > 为什么网格将线放在彼此下方(WPF)

问题描述

我需要将主菜单附加到第一个网格的行并将画布放入第二行。在运行时,我看到第二行渲染在第一行下。为什么?怎么了?

我可以从顶部设置边距,但这很糟糕,并且在这个项目中不需要。

截图: screen1

<Window x:Class="OlodimStories.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:OlodimStories"
        Title="Olodim Stories" 
        WindowState="Maximized"
        mc:Ignorable="d"
        ManipulationStarting="Window_ManipulationStarting"
        ManipulationDelta="Window_ManipulationDelta"
        ManipulationInertiaStarting="Window_InertiaStarting" Loaded="Window_Loaded">
    <Window.Resources>

        <MatrixTransform x:Key="InitialMatrixTransform">
            <MatrixTransform.Matrix>
                <Matrix OffsetX="200" OffsetY="200"/>
            </MatrixTransform.Matrix>
        </MatrixTransform>

    </Window.Resources>
    <Grid>
        <Canvas Name="rootCanvas" Background="Green" Grid.Row="1" Grid.Column="0"
                VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>

        <Menu Name="mainMenu" Height="24" VerticalAlignment="Top" HorizontalAlignment="Left" Background="Transparent" 
                  Grid.Row="0" Grid.Column="0">
            <MenuItem Header="Меню" FontSize="16">
                <MenuItem Header="Открыть" FontSize="16"></MenuItem>
                <MenuItem Header="Сохранить" FontSize="16" Click="MenuItem_Click"/>
                <MenuItem Name="addImageItem" FontSize="16" Header="Добавить изображение..." Click="AddImageItem_Click"/>
                <Separator />
                <MenuItem Name="exitApp" Header="Выход" FontSize="16"></MenuItem>
            </MenuItem>
        </Menu>


    </Grid>
</Window>

标签: c#wpfxaml

解决方案


<Grid.RowDefinitions>不见了:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Canvas Grid.Row="1" Grid.Column="0"/>
    <Menu Grid.Row="0" Grid.Column="0">
    </Menu>
</Grid>

推荐阅读