How can I define rows in a grid inside a grid using XAML?

Juan Dent 236 Reputation points
2022-08-05T17:28:03.71+00:00

I have this XAML:

<Window x:Class="MultiWindows.TreeViewControl"  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
        xmlns:local="clr-namespace:MultiWindows"  
        mc:Ignorable="d"  
        Title="TreeViewControl" Height="450" Width="800">  
    <Grid ShowGridLines="True" Name="grid">  
        <Grid.RowDefinitions>  
            <RowDefinition Height="29"/>  
            <RowDefinition Height="29"/>  
            <RowDefinition Height="90"/>  
        </Grid.RowDefinitions>  
        <Grid.ColumnDefinitions>  
            <ColumnDefinition Width="180" />  
            <ColumnDefinition Width="470" />  
            <ColumnDefinition Width="80" />  
  
        </Grid.ColumnDefinitions>  
  
        <TextBlock Text="hola" Name="textBlock1" Grid.Column="1" Grid.Row="1" Margin="6,6,0,0"/>  
        <TreeView x:Name="treeViewCountry" Width="180" Grid.Column="0" Grid.Row="2" Grid.RowSpan="2" >  
            <TreeViewItem Header="United States" >  
                <TreeViewItem Header="New York" />  
                <TreeViewItem Header="Los Angeles" />  
                <TreeViewItem Header="Chicago" />  
            </TreeViewItem>  
            <TreeViewItem Header="France" x:Name="french" >  
                <TreeViewItem Header="Paris" />  
                <TreeViewItem Header="Marseille" />  
                <TreeViewItem Header="Lyon" />  
                <TreeViewItem Header="Tolouse" />  
            </TreeViewItem>  
        </TreeView>  
  
        <Grid ShowGridLines="True" Name="gridinternal" Height="377"  Grid.Row="2"  Grid.Column="1" Grid.RowSpan="2" Margin="2,3,0,0">  
            <Grid.RowDefinitions>  
                <RowDefinition Height="29"/>  
                <RowDefinition Height="29"/>  
                <RowDefinition Height="29"/>  
                <RowDefinition Height="29"/>  
                <RowDefinition Height="29"/>  
                <RowDefinition Height="29"/>  
            </Grid.RowDefinitions>  
            <Grid.ColumnDefinitions>  
                <ColumnDefinition Width="80" />  
                <ColumnDefinition Width="240" />  
                <ColumnDefinition Width="80" />  
                <ColumnDefinition Width="80" />  
            </Grid.ColumnDefinitions>  
            <TextBlock Text="First Name" Grid.Row="1" TextAlignment="Center" VerticalAlignment="Center"/>  
            <TextBlock Text="Last Name" Grid.Row="2" TextAlignment="Center" VerticalAlignment="Center"/>  
            <TextBlock Text="Email" Grid.Row="3" Grid.Column="0" x:Name="email"/>  
        </Grid>  
    </Grid>  
</Window>  
  

The TextBlock with text "Email" is not displayed unless I add another RowDefinition to the outer grid!! but it is supposed to be in row 3 of the inner grid! What's hapenning?

Also I want the TreeView to cover the whole column 0 row 2 of the outer grid, how can I do that?

Please I am learning XAML

Developer technologies Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2022-08-05T18:57:08.933+00:00

    For example, replace <RowDefinition Height="90"/> with <RowDefinition Height="*"/>.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.