Dillinger
Dillinger

Reputation: 1903

Can't set specific column in Grid

I've created a TabItem with a default layout that have 3 columns and one row. Inside the first column I've inserted a StackPanel and put inside another Grid that have 3 columns and 3 rows. Now the problem's that inside the second Grid I've created a GroupBox with a StackPanel and I've set Grid.Column="2" but the controls inside the GroupBox doesn't go in the second column of the second Grid and I don't know what am I doing wrong. This is my code:

<TabItem Header="Confronto">
     <Grid>
           <Grid.ColumnDefinitions>
                 <ColumnDefinition Width="*" />
                 <ColumnDefinition Width="*" />
                 <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                  <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <StackPanel Grid.Column="0" Grid.Row="0">
                 <Grid>
                    <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="*" />
                         <ColumnDefinition Width="*" />
                         <ColumnDefinition Width="*" />
                     </Grid.ColumnDefinitions>
                     <Grid.RowDefinitions>
                          <RowDefinition Height="*"/>
                          <RowDefinition Height="*"/>
                          <RowDefinition Height="*"/>
                     </Grid.RowDefinitions>

                     <GroupBox Header="Informazioni Squadre" Height="Auto" Grid.ColumnSpan="3" Grid.RowSpan="3">
                            <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Grid.Column="2">
                                 <Label Content="Inter" FontWeight="Bold"></Label>
                                 <Canvas Height="75" Width="75" Background="Gray"></Canvas> 
                                 <Label Content="Italia" Margin="0,15,0,0"></Label>
                                 <Label Content="Serie A" Margin="0,10,0,0"></Label>
                                 <Label Content="97%" Margin="0,10,0,0"></Label>
                             </StackPanel>
                      </GroupBox>

                    </Grid>
              </StackPanel>
       </Grid>
 </TabItem>

Upvotes: 0

Views: 393

Answers (1)

dkozl
dkozl

Reputation: 33364

As mentioned in the comment you can set Grid.Column and Grid.Row only on direct children of the Grid. Your inner Grid has only one direct child (GroupBox) and Grid.Column \ Grid.Row will work only on that element.

You can reverse the order and put inner Grid inside GroupBox. As a side not Grid.Column="2" will put it in the 3rd column of the inner Grid not the second (it's indexed from 0)

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel Grid.Column="0" Grid.Row="0">
        <GroupBox Header="Informazioni Squadre" Height="Auto">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Grid.Column="2">
                    <Label Content="Inter" FontWeight="Bold"></Label>
                    <Canvas Height="75" Width="75" Background="Gray"></Canvas>
                    <Label Content="Italia" Margin="0,15,0,0"></Label>
                    <Label Content="Serie A" Margin="0,10,0,0"></Label>
                    <Label Content="97%" Margin="0,10,0,0"></Label>
                </StackPanel>
            </Grid>
        </GroupBox>
    </StackPanel>
</Grid>

Upvotes: 1

Related Questions