Wpf - 使用行和列定义的网格 - 如何忽略某些行的列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36399356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:44:15  来源:igfitidea点击:

Wpf - Grid using row and column definition - How to ignore columns for some rows

wpfxamllistviewgrid-layoutgroupbox

提问by Mandersen

I'm trying to use the grid row / column definitions in my wpf application. At the moment, I need to implement a list view inside a GroupBox. Here I need to ignore the column definitions i set in the top in the view.

我正在尝试在我的 wpf 应用程序中使用网格行/列定义。目前,我需要在 GroupBox 中实现一个列表视图。这里我需要忽略我在视图顶部设置的列定义。

Row and column definitions:

行列定义:

        <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="260" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="250" />
        <ColumnDefinition Width="20" />
        <ColumnDefinition Width="180" />
        <ColumnDefinition Width="20" />
        <ColumnDefinition Width="180" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

Here you see I have a rowDefinition with a height of 260. This should contain my list view. The problem is that it's inside the columns I have made and therefore it won't take all space. Is there somehow a setting so that this row will ignore the columns I have set? I still want the columns to be used for the other rows.

在这里你会看到我有一个高度为 260 的 rowDefinition。这应该包含我的列表视图。问题是它在我制作的列内,因此它不会占用所有空间。是否有某种设置可以使这一行忽略我设置的列?我仍然希望将列用于其他行。

Here you see a picture of how it looks:

在这里,您可以看到它的外观图片:

enter image description here

在此处输入图片说明

Hope someone can help, good day.

希望有人能帮忙,美好的一天。

回答by StepUp

Just use attached property Grid.ColumnSpan:

只需使用附加属性Grid.ColumnSpan

<ListView Grid.ColumnSpan="6"/>

It will extend your ListViewfor 6 columns.

它将扩展您ListView的 6 列。

Simple advice about your UI:

关于您的用户界面的简单建议:

I suggest you to create you resizable XAML, not static. I mean it is not good:

我建议您创建可调整大小的 XAML,而不是静态的。我的意思是它不好:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="260" />
    <RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="250" />
    <ColumnDefinition Width="20" />
    <ColumnDefinition Width="180" />
    <ColumnDefinition Width="20" />
    <ColumnDefinition Width="180" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

However, it is better:

但是,它更好:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="3*" />
    <RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="0.5*" />
    <ColumnDefinition Width="2*" />
    <ColumnDefinition Width="0.5*" />
    <ColumnDefinition Width="2*" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

It gives resizable UI(XAML) at any display.

它在任何显示器上提供可调整大小的 UI(XAML)。

回答by Nitin

You can set Grid.ColumnSpan="6"on your listview. It will expand in the row.

您可以Grid.ColumnSpan="6"在列表视图上进行设置。它将在行中扩展。

<ListView Grid.ColumnSpan="6"/>

回答by Grand Julivan

depends on how you want to display the listview.

取决于您希望如何显示列表视图。

you can add another grid, just to be safe, that you will want to add something later on that row.

为了安全起见,您可以添加另一个网格,稍后您将希望在该行添加一些内容。

<Grid grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6">
  <ListView> </ListView>
</Grid>