WPF网格不垂直拉伸 [英] WPF Grid is not stretching vertically

查看:144
本文介绍了WPF网格不垂直拉伸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主窗口中的下列电网

 <电网NAME =gridMainWIDTH =自动VerticalAlignment =拉伸HEIGHT =自动> 
< /网格和GT;



我加入一个用户控件在动态网格。主窗口只有这个网格。我想网格进行横向和纵向拉伸,应填写了整个窗口。网格是横向拉伸,但不垂直拉伸即可。知道为什么吗?什么我需要做的,使垂直网格拉伸?



修改



下面是完整的XAML。

 <窗口x:类=Sensitech.TurboValidator.UserControls.ConveyorBelt
的xmlns =HTTP:/ /schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
标题=ConveyorBelt身高=329WIDTH =714的xmlns:我=CLR的命名空间:System.Windows.Controls.DataVisualization.Charting;装配= System.Windows.Controls.DataVisualization.Toolkit>
<电网NAME =gridMainWIDTH =自动VerticalAlignment =拉伸HEIGHT =自动背​​景=青色>

< /网格和GT;
< /窗GT;


解决方案

尝试设置行高*

 <电网NAME =gridMain> 
< Grid.RowDefinitions>
< RowDefinition高度=*/>
< /Grid.RowDefinitions>
< /网格和GT;



同样定义ColumnDefinition并设置宽度为*



另外,还要确保电网不拉伸不是用户控制的人。您可以轻松地做到这一点通过分配一些背景颜色为网格。


I've the following Grid in the main window:

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

I'm adding a UserControl dynamically in the grid. The main window only has this grid. I want the grid to be stretched both horizontally and vertically and should fill up entire window. The grid is stretching horizontally but doesn't stretch vertically. Any idea why? What do I need to do to make the grid stretch vertically?

EDIT

Here is the complete 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>

解决方案

Try setting row height to *

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

Similarly define ColumnDefinition and set Width to *

Also make sure grid is the one not stretching not the user control. You can easily do that by assigning some background color to Grid.

这篇关于WPF网格不垂直拉伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆