0

我刚开始使用 WPF,我正在尝试设置一个包含四行高度为 150 的网格。这将占用我为高度设置的 800 个像素中的 600 个。然后,我将上边距设置为 30,将下边距设置为 170,以便为底部的控件留出一些空间。

设计视图中的一切看起来都很棒,但是当我运行我的应用程序时,底行有一些区域被截断。

设计视图 在此处输入图像描述

运行视图 在此处输入图像描述

我不明白是什么导致了这些观点之间的这种差异。

 <Page x:Class="EzTargetProject.HomePage"
  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" 
  mc:Ignorable="d" 
  d:DesignHeight="800" d:DesignWidth="1280"
Title="HomePage">

<Grid  Margin="20,30,20, 170" Grid.Column="4" Grid.Row="4" Background="Gray" ShowGridLines="True">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="150"/>
        <RowDefinition Height="150"/>
        <RowDefinition Height="150"/>
        <RowDefinition Height="150"/>
    </Grid.RowDefinitions>

    <!-- Name -->
    <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Vertical" />
</Grid>

4

1 回答 1

1

如果要设置网格的高度,可以避免底部边距。

如果你总是想要一个 600px 高度的网格,只需设置它。

我会使用 ScrollViewer 作为父级,让用户看到您要在网格下设置的控件(例如,如果用户想要一个小窗口): 在 WPF 中启用滚动条

于 2013-02-16T17:58:46.723 回答