views:

776

answers:

1

Hi there,

Is there a way to combine rows within a specific column? Hence to get something like this (I am currently using rowspan on a control i.e. Image but is there a better way?)

    --------------------
    |         |--------|
    |         |--------|
    |         |--------|
    |         |--------|
    |         |--------|
    --------------------

I am using this code basically

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

Which gives me something like this (notice the rows also appear in column 0)

    --------------------
    |---------|--------|
    |---------|--------|
    |---------|--------|
    |---------|--------|
    |---------|--------|
    --------------------

Now i can get around this for example if i want to place a image i can use RowSpan, but is it not possible to design a column with no rows and the other columns having rows?

+1  A: 

This is not possible with the Grid control. Rows pass through all columns, and columns pass through all rows. As you've found, the RowSpan and ColumnSpan allow you to have a control span multiple rows or columns respectively.

One other potential workaround is to host one Grid within another:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Image/>

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

HTH, Kent

Kent Boogaart
Thanks kent, but i suppose the extra code bloat isn't worth it? .. I presume its better to continue using my grid and just use RowSpan etc?
mark smith
@Mark: yeah, judging by your description I'd say `RowSpan` is the easiest way to achieve your goal.
Kent Boogaart