karun_r
karun_r

Reputation: 183

Grid row hiding child other elements

I have the following simple WPF code where my expectation is to create a 2 rows 3 columns grid with grid splitters on the columns. But the grid splitters are visible and working fine as long as I don't split the rows in the grid.

Below is the sample code:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="100" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="30"  />
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <GridSplitter Grid.Column="1"
                  Grid.RowSpan="2"
          HorizontalAlignment="Left" 
          VerticalAlignment="Stretch"
          Background="LightGray" 
          ShowsPreview="true"
          Width="3" />
    <GridSplitter Grid.Column="2"
                  Grid.RowSpan="2"
          HorizontalAlignment="Left" 
          VerticalAlignment="Stretch"
          Background="LightGray" 
          ShowsPreview="true"
          Width="3"/>
    <!--Button x:Name="button" Grid.Row="1" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Height="27" Grid.Column="1" Margin="19,42,0,0" /-->
</Grid>

I gave the Grid.RowSpan = 2 thinking that it would make the grid splitter span over the two rows that I have. However, when I run this code, I am getting this.

enter image description here The second row is over lapping the the grid splitters and they are not visible. The blue line represents the outline. I just want the vertical grid splitters to span over the entire window. What am I doing wrong here? I even declared the grid splitters at the bottom.

Upvotes: 0

Views: 46

Answers (1)

ASh
ASh

Reputation: 35646

the only problem with multiple rows in your sample is that they don't take full height of the Grid.

1st row has 30 height, 2nd has a height depending on content (Auto). without any content it will be 0. blue lines on screenshot don't show the real outline. to fix the layout make 2nd row fill the height: Height="*"

<Grid.RowDefinitions>
    <RowDefinition Height="30"  />
    <RowDefinition Height="*"/>
</Grid.RowDefinitions>

Upvotes: 1

Related Questions