The grid in WPF currently has a grid system like this:
Cols
+ + + + +
| 0 | 1 | 2 | 3 |
+--+---|---|---|---|---
0 | | | | |
+--+---|---|---|---|--- Rows
1 | | | | |
+--+---|---|---|---|---
2 | | | | |
+--+---|---|---|---|---
Is there a way to make it behave like this:
Cols
+ + + + +
| 0 | 1 | 2 | 3 |
+--+---|---|---|---|---
2 | | | | |
+--+---|---|---|---|--- Rows
1 | | | | |
+--+---|---|---|---|---
0 | | | | |
+--+---|---|---|---|---
Ideally I would like the RowSpan to extend an item upwards instead of downwards.
Example:
My datasource stores a cube on the map as 0,0 with the intent of it being displayed on the bottom left corner. However the grid in WPF will put that cube on the top left. The other problem is the datasource gives me a 2×2 with the position of the bottom left “anchor” position with a width and height. The width and height are bound to ColSpan and RowSpan. The RowSpan is an issue because it will be expanded down the grid and not up.
You should be able to do this without having to create a custom or user control by using attached properties.
Here’s a class that I think should be able to do what you want. Instead of binding the values of
Grid.RowandGrid.RowSpanto your row and height, bindGridEx.RowFromBottomandGridEx.RowSpanFromBottomto them. The property change handlers for these properties will compute the new value ofGrid.Rowbased on the values of those properties and the number of rows in the grid.One potential problem is that this may not update correctly if you’re adding or subtracting rows from the grid at runtime.
If you have any questions about what’s going on here, feel free to ask.