bleepzter
bleepzter

Reputation: 9985

How to hide a the contents of a ColumnDefinition

I have a SL4 user control which uses a grid for it's layout. The grid is as follows:

<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    <Grid.RowDefinitions>
        <RowDefinition x:Name="LayoutHeaderRow"    Height="30"/>
        <RowDefinition x:Name="LayoutSubHeaderRow" Height="30"/>
        <RowDefinition x:Name="LayoutContentRow"   Height="*"/>
        <RowDefinition x:Name="LayoutFooterRow"    Height="30"/>
    </Grid.RowDefinitions>
</Grid>

My question is how do I hide the LayoutSubHeaderRow and it's contents?

Thanks!

Martin

Upvotes: 3

Views: 215

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189437

You've added x:Name to row definitions but that is not much use to you because RowDefinition elements are not visual elements and do not end up in the visual tree. Hence FindName can't find them.

Your xaml needs to look like this:-

<Grid x:Name="Layout" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    <Grid.RowDefinitions>
        <RowDefinition  Height="30"/>
        <RowDefinition Height="30"/>
        <RowDefinition  Height="*"/>
        <RowDefinition  Height="30"/>
    </Grid.RowDefinitions>
</Grid>

You can use the ordinal position of desired row to pick it out of the RowDefinitions collection and manipulate it in code

    Layout.RowDefinitions[1].Height = new GridLength(0);

Upvotes: 3

Related Questions