Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid inside Grid in XAML

Tags:

I want to have a childGrid in second column of parentGrid (in childGrid I want to have two columns: first for label, second for textbox)

How can I do Something like that? I tried the following code:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Height="*"/>
        <ColumnDefinition Height="*"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column=1>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Height="*"/>
            <ColumnDefinition Height="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    </Grid>
</Grid>
like image 842
user278618 Avatar asked Jul 06 '10 10:07

user278618


People also ask

How do I create a Grid in XAML?

First Method: By typing XAML CodeRowDefinitions property and a ColumnDefinition Element for each column inside the Grid. ColumnDefinitions property. By default, GridLines are invisible. For showing the GridLines, set the ShowGridLines property of the Grid to True.

How do you define a Grid in XAML?

In XAML a Grid is made up of a series of rows and columns. By specifying the row and column of an element within a Grid, you can place and space other elements within a user interface. Rows and columns are defined with the RowDefinition and ColumnDefinition elements.

How do I create a dynamic Grid in WPF?

The Grid class in WPF represents a Grid control. The following code snippet creates a Grid control, sets its width, horizontal alignment, vertical alignment, show grid lines, and background color. Grid DynamicGrid = new Grid();

What are the child elements of a Grid called?

A child Rectangle element ( rect1 ) is added to the Grid in column position zero, row position zero. Button elements represent methods that can be called to reposition the Rectangle element within the Grid. When a user clicks a button, the related method is activated.


1 Answers

Based on your code, just fixed up a little:

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

Note that ColumnDefinition don't have a Height - they have a Width. You also need to define the ColumnDefinitions and RowDefinitions separately - you have them mixed together in your outer grid. I removed the RowDefinitions from the outer grid because you don't appear to be using them. Your inner grid has two columns and four rows.

like image 68
slugster Avatar answered Sep 21 '22 16:09

slugster