Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide a row in a WPF grid?

Tags:

wpf

grid

I have been hiding a row in a WPF grid by setting the Height property to 0.

I was expecting something akin to a Visible property.

Is there a more appropriate way to hide the row?

like image 674
Montgomery 'monty' Jones Avatar asked Mar 26 '10 08:03

Montgomery 'monty' Jones


1 Answers

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# for collapse :

name1.Height = new GridLength(0);
name2.Height = new GridLength(0);

C# for visibility:

name1.Height = new GridLength(1, GridUnitType.Star);
name2.Height = GridLength.Auto;
like image 159
Stephane G. Avatar answered Oct 02 '22 12:10

Stephane G.