c# - 为什么网格将线放在彼此下方(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>
解决方案
<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>
推荐阅读
- c# - C# 自定义滚动笛卡尔图
- python - Python - 使用带有列表的 YAGMAIL 发送邮件
- flask - 如何使用 jwt 刷新令牌
- binding - 列表控件未与 JSON 模型绑定 - SAPUI5
- mysql - 如何在 GROUP BY 中找到具有多列的 MAX 值?
- javascript - ajax 调用不适用于删除记录
- c# - 有没有办法调用正在运行的 WinForms 程序的方法并为另一个 WinForms 程序的方法设置参数?
- google-sheets - 根据从电子表格中另一个单元格中的值获得的引用获取单元格中的值
- spring-boot - Jenkins 未能执行目标 Maven 发布
- java - 无法访问 openapi-generator-cli.jar 文件