Wpf - 使用行和列定义的网格 - 如何忽略某些行的列
Wpf - Grid using row and column definition - How to ignore columns for some rows
我正在尝试在我的 wpf 应用程序中使用网格行/列定义。目前,我需要在 GroupBox 中实现一个列表视图。在这里我需要忽略我在视图顶部设置的列定义。
行和列定义:
<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>
在这里您可以看到我有一个高度为 260 的 rowDefinition。这应该包含我的列表视图。问题是它在我制作的列中,因此不会占用全部 space。是否有某种设置使该行将忽略我设置的列?我仍然希望这些列用于其他行。
在这里你可以看到它的外观图片:
希望有人能提供帮助,美好的一天。
只需使用附件 属性 Grid.ColumnSpan
:
<ListView Grid.ColumnSpan="6"/>
它将扩展您的 ListView
6 列。
关于您的简单建议 UI:
我建议您创建可调整大小的 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>
不过,更好的是:
<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>
它在任何显示时都提供可调整大小的 UI(XAML)。
您可以在列表视图中设置 Grid.ColumnSpan="6"
。它将在行中展开。
<ListView Grid.ColumnSpan="6"/>
取决于您希望如何显示列表视图。
您可以添加另一个网格,为了安全起见,稍后您会想在该行添加一些内容。
<Grid grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6">
<ListView> </ListView>
</Grid>
我正在尝试在我的 wpf 应用程序中使用网格行/列定义。目前,我需要在 GroupBox 中实现一个列表视图。在这里我需要忽略我在视图顶部设置的列定义。
行和列定义:
<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>
在这里您可以看到我有一个高度为 260 的 rowDefinition。这应该包含我的列表视图。问题是它在我制作的列中,因此不会占用全部 space。是否有某种设置使该行将忽略我设置的列?我仍然希望这些列用于其他行。
在这里你可以看到它的外观图片:
希望有人能提供帮助,美好的一天。
只需使用附件 属性 Grid.ColumnSpan
:
<ListView Grid.ColumnSpan="6"/>
它将扩展您的 ListView
6 列。
关于您的简单建议 UI:
我建议您创建可调整大小的 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>
不过,更好的是:
<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>
它在任何显示时都提供可调整大小的 UI(XAML)。
您可以在列表视图中设置 Grid.ColumnSpan="6"
。它将在行中展开。
<ListView Grid.ColumnSpan="6"/>
取决于您希望如何显示列表视图。
您可以添加另一个网格,为了安全起见,稍后您会想在该行添加一些内容。
<Grid grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6">
<ListView> </ListView>
</Grid>