我曾通过将 Height
属性设置为 0 来隐藏 WPF 网格中的一行。
我本希望有一种类似于 Visible
属性的方式。
是否有更合适的方法来隐藏该行?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderThickness="1" BorderBrush="Red"><TextBlock>Visible Row</TextBlock></Border>
<Border Grid.Row="1" BorderThickness="1" BorderBrush="Black" Visibility="Collapsed"><TextBlock>Hidden Row</TextBlock></Border>
<Border Grid.Row="2" BorderThickness="1" BorderBrush="Red"><TextBlock>Visible Row</TextBlock></Border>
</Grid>
实际上我几天前也问了同样的问题,你可以看看这里:
基本上将RowHeight设置为Auto,然后将Visibility="Collapsed"设置为隐藏行即可。我遇到的唯一问题是边距,但那只是次要问题。至少行被隐藏了。
Just do this :
XAML :
<Grid.RowDefinitions>
<RowDefinition Height="1*" x:Name="name1" />
<RowDefinition Height="Auto" x:Name="name2" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
C#的崩溃处理:
name1.Height = new GridLength(0);
name2.Height = new GridLength(0);
C#为可见性:
name1.Height = new GridLength(1, GridUnitType.Star);
name2.Height = GridLength.Auto;