在WPF网格Independants宽度 [英] Independants width in a WPF Grid

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

问题描述

我有2行和在WPF 2列的网格。我想,该列的宽度是独立的每一行。我试图自动,但没有成功。这里是为了解释一个画面:

I have a grid with 2 rows and 2 columns in WPF. I would like that the column widths are independent for each row. I tried "auto", but no success. Here is a picture in order to explain :

我怎样才能做到这一点使用网格?

How can I accomplish this using grid?

推荐答案

如果你必须使用一个网格布局,那么你有两个选择:

If you must use a grid layout, then you have a couple of options:

选项1:使每行一列,然后窝在每一行中网格你想独立列:

Option 1: Make each row a single column and then nest a grid in each row you would like independent columns:

XAML

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>

    <TextBlock Text="AAAAAAAAAAAAAAAAAAAA" />

    <Grid Grid.Row="1">
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
      </Grid.ColumnDefinitions>

      <TextBlock Text="BBBBBBB"">
      <TextBlock Grid.Column="1" Text="CCCCCCC" />
    </Grid>
</Grid>

选项2:利用ColumnSpan在行:

Option 2: Make use of ColumnSpan in the rows:

XAML

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition />
    <RowDefinition />
  </Grid.RowDefinitions>

  <Grid.ColumnDefinitions>
    <ColumnDefinition />
    <ColumnDefinition />
  </Grid.ColumnDefinitions>

      <TextBlock Grid.ColumnSpan="2" Text="AAAAAAAAAAAAAAAAAAAA" />
      <TextBlock Grid.Row="1" Text="BBBBBBB"">
      <TextBlock Grid.Row="1" Grid.Column="1" Text="CCCCCCC" />
    </Grid>
</Grid>



*这些是没有一个编辑器类型的,可能需要一些调整。

*These were typed without an editor and may need a bit of tweaking.

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

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