隐藏WPF中的网格行 [英] Hide grid row in WPF

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

问题描述

我有一个简单的WPF表单,并在窗体上声明了 Grid Grid 有很多行:

I have a simple WPF form with a Grid declared on the form. This Grid has a bunch of rows:

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" MinHeight="30" />
    <RowDefinition Height="Auto" Name="rowToHide" />
    <RowDefinition Height="Auto" MinHeight="30" />
</Grid.RowDefinitions>

名为 rowToHide 的行包含几个输入字段,我想在我检测到我不需要这些字段后隐藏这一行。很简单,只需将 Visibility = Hidden 设置为行中的所有项目,但该行仍占用 Grid 。我尝试将 Height = 0 设置为这些项目,但这似乎不起作用。

The row named rowToHide contains a few input fields and I want to hide this row after I detect I don't need these fields. It's simple enough to just set Visibility = Hidden to all items in the row, but the row still takes up space in the Grid. I tried setting Height = 0 to the items, but that didn't seem to work.

您可以考虑它是这样的:你有一个表单,在那里你有一个下拉菜单,说支付类型,如果这个人选择现金,你想隐藏包含卡详细信息的行。这不是一个选项,已经隐藏起来了。

You can think of it like this: You have a form, in there you have a drop down saying "Payment Type", and if the person selects "Cash", you want to hide the row containing the Card details. It isn't an option to start the form with this hidden already.

推荐答案

你也可以通过引用Row in然后改变行的高度本身。

You can also do this by referencing the Row in the Grid and then changing the Height of the row itself.

XAML

<Grid Grid.Column="2" Grid.Row="1" x:Name="Links">
   <Grid.RowDefinitions>
      <RowDefinition Height="60" />
      <RowDefinition Height="*" />
      <RowDefinition Height="*" />
      <RowDefinition Height="80" />
   </Grid.RowDefinitions>
</Grid>

VB.NET

If LinksList.Items.Count > 0 Then
   Links.RowDefinitions(2).Height = New GridLength(1, GridUnitType.Star)
Else
   Links.RowDefinitions(2).Height = New GridLength(0)
End If

尽管网格中的元素折叠也起作用,但如果这样做更简单一些网格中有许多项目没有可以折叠的封闭元素。这将提供一个很好的选择。

Whilst the Collapsing of the elements within the Grid also works, this is a bit simpler if you have many items in the Grid that does not have an enclosing element that can be collapsed. This would provide a good alternative.

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

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