Search code examples
c#wpfuniformgrid

UniformGrid Layout


I know that Uniform grid does not support row span, but its somehow possible by overriding a method from what i read on Google, but i could really use an example how can i do this. What i want to achieve is a layout similar to this:

 ----------
|  1  | 2  |
 ----------
|    3     |
 ---------- 

So basically i want the third children to be spanned over 2 columns. I could use a grid but sadly i don't know any method how can i do this because all the children's are created dynamically and i cannot specify in witch cell the child will be put.


Solution

  • I think that you'd be better off using a Grid control. Although you say that you cannot specify in which cell the child will be put, I would try to fix that problem, rather than to create a new control. If you can fix that issue, then this might help you.

    To populate a particular row in code, you can use the Grid.SetRow method and to populate a particular column, you can use the Grid.SetColumn method:

    Grid.SetRow(rectangle, 1);
    Grid.SetColumn(rectangle, 1);
    

    Likewise, to set a row span, you can use the Grid.SetRowSpan method and to set a column span, you can use the Grid.SetColumnSpan method:

    Grid.SetRowSpan(rectangle, 2);
    Grid.SetColumnSpan(rectangle, 2);
    

    Please see the Grid.SetRow Method, Grid.SetRowSpan Method , Grid.SetColumn Method and Grid.SetColumnSpan Method pages on MSDN for a full example on this.