wpf - XAML 窗口看起来不像我想要的
问题描述
我正在学习 WPF,我正在 XAML 中创建一个窗口。
窗口应如下所示:
但是当我运行程序时,它看起来像这样:
代码如下:
<Page x:Class="WpfApp1.ProductsManagement"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="ProductsManagement">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="420" />
</Grid.RowDefinitions>
<TextBlock
Margin="5"
Text="Search"
Grid.Row="0"
Grid.Column="0"/>
<TextBox
Margin="5"
Grid.ColumnSpan="2"
Grid.Column="1"
Background ="White"
Grid.Row="0"
Text="hi"/>
<DataGrid
Margin ="5"
Name="dataGrid"
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="1"/>
<Border
Margin ="5"
Grid.Row="1"
Grid.Column="2"/>
</Grid>
</Page>
欢迎任何意见或建议。
更新
我以下面的代码为例:
<Page x:Class="WpfApp1.Discussion"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:data="clr-namespace:BikeShop"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Discussion">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<ListBox
Grid.ColumnSpan="2"
Margin="5"/>
<Button
Grid.Row="1"
Grid.Column="1"
Margin="5"
Content="Send" />
<TextBox
Grid.Row="1"
Margin="5"
Text="Type your message here" />
</Grid>
</Page>
当我运行代码时,它看起来像这样:(它工作正常)
解决方案
您的 RowDefinitions 必须是这样的:
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
现在你要求为第一行填充整个页面并将第二行设置为 420 的高度。
您必须为第一个定义特定值,为第二个定义 *。
您在设计器中看不到错误,因为您将第二行设置为 420。显然您在 30 处看到了第一行。但是当您进入全屏时,第一行变得更大。
推荐阅读
- html - 子域可以在父域上设置cookie吗
- c# - C# - 通过用户输入值减去 int
- solr - Solr - 配置建议搜索子字符串
- unique - NestJS TypeORM - 为什么实体中的唯一约束会引发异常并使应用程序崩溃
- c# - 如何使用 C# 在另一台显示器 (HDMI) 中流式传输媒体文件?
- ssl-certificate - 握手失败,出现致命错误 SSL_ERROR_SSL: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
- swift - 如何将 UITextView 添加到 UITableView 的底部
- swift - 运行后台定时器 Swift
- vue.js - 将 .env 文件与 vue.config.js 关联
- go - 当另一个对象告诉 Struct 更新时,Struct 字段不更新