Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use WPF Grid without specifying absolute cell coordinates for every item?

Tags:

wpf

xaml

grid

My typical form with Grid look like this in XAML:

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

        ....

        <TextBlock Grid.Row="6" Text="Component"/>
        <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Component.Name}"></TextBox>
        <TextBlock Grid.Row="7" Text="Bussiness Process"/>
        <TextBox Grid.Row="7" Grid.Column="1" Text="{Binding BusinessProcess.Name}"></TextBox>

    </Grid>

Is there a way to avoid specifying th exact Row/Column coordinates?

Basically, I would like to be able to reorder my controls in the Grid quickly by copying XAML around and now I have to change the coordinates which is awkward. I don't want to reorder them in the Designer because it adds some unnecessary properties to the items.

like image 753
Max Galkin Avatar asked Sep 25 '09 16:09

Max Galkin


1 Answers

No. Unfortunately, the Grid works by having the Grid.Row and Grid.Column attached properties defined on the children - they must be specified on each child.

BTW - Blend does a better job of letting you move these things around without the "extra" properties appearing. You may want to try giving that a shot for these types of situations.

like image 130
Reed Copsey Avatar answered Sep 22 '22 11:09

Reed Copsey