Sharing Layout Size Info Between Multiple Grids

Filed in Software Developement Leave a comment

The title should probably be enough, but in case it isn’t I am talking about multiple grids in a single view that need to share row size or column size. A good example of this would be if you wanted to split grid rows up into groups, then apply each group to an expander, thus allowing you to show and collapse the different groups of rows. However, when everything is expanded, you still want all your columns to line up. Well, you can use the Grid.IsSharedSizeScope attached property for this. There are some msdn docs on this here, but i found them to be somewhat lacking in detail. So here is is my idiot proof guide (really just the information left out of the msdn article) on how to share grid layout size info.

The most important thing to note is that you only use the attached property to enable (or disable) a scoped region to share size info within. This is extremely important to understand because scope is not inherited by children if you override it. For example, if you were to create a grid within a grid and put the attached property on both grid nodes, the second grid would override the scope of the first, and you would NOT get your shared sizing. You only ever want to put the attached property ONCE for the ENTIRE scope of shared sizing.

With that out of the way, all you need to do now is give your row or column definitions a unique identifier on the SharedSizeGroup property and then all rows or columns that share the same unique identifier will also share the same hight or width respectively. You should also note that this only works for explicit or Auto sized rows and columns. If you specify a star on a shared item, it will default it to Auto.

, , ,

TOP