c# - WPF 网格不垂直拉伸(stretch)

标签 c# wpf user-interface grid

我在主窗口中有以下 Grid:

<Grid Name="gridMain" Width="Auto" VerticalAlignment="Stretch" Height="Auto">
</Grid>

我正在网格中动态添加一个 UserControl。主窗口只有这个网格。我希望网格在水平和垂直方向上都被拉伸(stretch),并且应该填满整个窗口。网格水平拉伸(stretch)但不垂直拉伸(stretch)。知道为什么吗?我需要做什么才能使网格垂直拉伸(stretch)?

编辑

这是完整的 XAML。

<Window x:Class="Sensitech.TurboValidator.UserControls.ConveyorBelt"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ConveyorBelt" Height="329" Width="714" xmlns:my="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">
    <Grid Name="gridMain" Width="Auto" VerticalAlignment="Stretch" Height="Auto" Background="Cyan">

    </Grid>
</Window>

最佳答案

尝试将行高设置为*

<Grid Name="gridMain" >    
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
</Grid>

同样定义ColumnDefinition,设置Width为*

还要确保网格是不拉伸(stretch)的而不是用户控件。您可以通过为 Grid 分配一些背景颜色来轻松做到这一点。

关于c# - WPF 网格不垂直拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8641456/

相关文章:

c# - 如何在 accord.net 中保存“学习状态”?

c# - Xamarin 表单错误 : Java. Lang.NoClassDefFoundError : android. support.graphics.drawable.VectorDrawableCompat

c# - C# 中的观察者模式

c# - 显示 ICollectionView 的前 X 项

wpf - ListView 组标题显示多次

java - 有没有办法将线程的命运与对象联系起来?

java - 帮助: 8 X 10 2-dimensional array of buttons in android

c# - ASP.NET - C# 与 VB.NET - 间接差异和您最初可能不会考虑的事情

c# - 将项目添加到在后台线程上创建的 ObservableCollection

matlab - MATLAB 中的两个等待栏