Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: How to combine Rows within a column (alternative to rowspan)?

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?

like image 289
mark smith Avatar asked Sep 27 '09 12:09

mark smith


2 Answers

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>
like image 151
Kent Boogaart Avatar answered Nov 20 '22 19:11

Kent Boogaart


How about something like this:

            <StackPanel Orientation="Horizontal">
                <Grid Height="100" Width="50"></Grid>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150" />
                    </Grid.ColumnDefinitions>
                </Grid>
            </StackPanel>
like image 1
ManeeshK Avatar answered Nov 20 '22 21:11

ManeeshK