gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:08:26 24 4
gpt4 key购买 nike

我在主窗口中有以下 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com