user3095715
user3095715

Reputation: 77

Create multiple rows and columns xaml

i need to create a lot of rows and columns in order to manage my custom controls correctly. So my question is if it is possible to achieve the same result as the code shown below? In a more clean way, this feels so unpractical...

<Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>

Upvotes: 3

Views: 6877

Answers (3)

Lee O.
Lee O.

Reputation: 3312

Another alternative to Wouter's answer of AutoGrid is ApexGrid. The code would look very similar to AutoGrid.

<apex:ApexGrid Rows="Auto,*" Columns="100,Auto">
   <Label Grid.Row="0" Grid.Column="0" />
   <TextBox Grid.Row="0" Grid.Column="1" />
   <Label Grid.Row="1" Grid.Column="0" />
   <TextBox Grid.Row="1" Grid.Column="1" />
</apex:ApexGrid>

Upvotes: 0

Wouter
Wouter

Reputation: 2262

You could have a look at AutoGrid for syntax as follows:

<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto">
  <Label />
  <TextBox />
  <Label />
  <TextBox />
</AutoGrid>

Upvotes: 4

Roland
Roland

Reputation: 398

You can do the same in code behind, but usually you should to do that in XAML like you did.

        // Add 10 Rows
        for (int i = 0; i < 10; i++)
        {
            var height = GridLength.Auto;
            if (i == 0)
                height = new GridLength(1, GridUnitType.Star);
            layoutGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = height
            });    
        }

        // Add 7 Columns
        for (int i = 0; i < 7; i++)
        {
            var width = GridLength.Auto;
            if (i == 0)
                width = new GridLength(1, GridUnitType.Star);
            layoutGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = width
            });
        }

Upvotes: 2

Related Questions