WPF网格没有垂直拉伸

Don*_*alo 4 c# wpf grid user-interface

Grid在主窗口中有以下内容:

<Grid Name="gridMain" Width="Auto" VerticalAlignment="Stretch" Height="Auto">
</Grid>
Run Code Online (Sandbox Code Playgroud)

UserControl在网格中动态添加.主窗口只有这个网格.我希望网格水平和垂直拉伸,并应填满整个窗口.网格水平拉伸但不垂直拉伸.知道为什么吗?我需要做什么才能使网格垂直伸展?

编辑

这是完整的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>
Run Code Online (Sandbox Code Playgroud)

Har*_*san 13

尝试将行高设置为*

<Grid Name="gridMain" >    
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
</Grid>
Run Code Online (Sandbox Code Playgroud)

类似地定义ColumnDefinition并将Width设置为*

还要确保网格不是拉伸而不是用户控件.您可以通过为网格指定一些背景颜色来轻松实现.