tags:

views:

170

answers:

2

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?

Thanks,

E

+1  A: 

You could set the visibility of the row's content to "Collapsed". This will only work if the Height property of the RowDefinition is set to "Auto" so the row sizes based on it's content.

For example,

<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>
IanR
Exactly what I was looking for. Thanks.
elggarc
A: 

I actually just asked the same question a couple of days ago, take a look here:

http://stackoverflow.com/questions/2502178/wpf-hide-grid-row

Basically setting the RowHeight to Auto and then Setting the Visibility="Collapsed" will hide the row for you. The only issue I had was the Margins, but that was minor. At least the row got hidden.

Richard
Good point about the margins, thanks.
elggarc