Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid's SharedSizeGroup and * sizing

I have a user control, call it UserControl, that has a grid with the following column definitions:

<Grid.ColumnDefinitions>             <ColumnDefinition Width="Auto" SharedSizeGroup="A"/>             <ColumnDefinition Width="Auto" SharedSizeGroup="B"/>             <ColumnDefinition Width="*" SharedSizeGroup="C"/>             <ColumnDefinition Width="Auto" SharedSizeGroup="D"/>             <ColumnDefinition MinWidth="30" Width="*" SharedSizeGroup="E"/>             <ColumnDefinition MinWidth="30" Width="*" SharedSizeGroup="F"/>             <ColumnDefinition Width="110" SharedSizeGroup="G"/>             <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="H"/>             <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="I"/>             <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="J"/>             <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="K"/>             <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="L"/> </Grid.ColumnDefinitions> 

I also have MainWindow, which contains a grid itself, with the following property defined on the grid:

Grid.IsSharedSizeScope="True" 

Now, I added a couple of UserControls to the grid in MainWindow (each to a separate row). My goal is to have each of the column widths of the different UserControls to remain in sync. Everything works fine when using SharedSizeGroup except for one thing. It seems that any column with a Width of * does not behave as it should. It looks like the * column widths are set as if they were Auto instead.

Are there any limitations/issues with SharedSizeGroup and * sizing? This seems like the best way to keep the column widths in sync but I can't seem to fix this.

Thanks.

like image 575
Flack Avatar asked Jan 11 '11 23:01

Flack


People also ask

What is SharedSizeGroup WPF?

You can use the SharedSizeGroup attribute to share column sizes across different grids. You can't normally share sizes of star-sized columns across multiple grids, however, since star sizing works only in the context of the current grid.


1 Answers

DefinitionBase.SharedSizeGroup Property (Microsoft Docs):

Columns and rows that participate in size-sharing do not respect Star sizing. In the size-sharing scenario, Star sizing is treated as Auto

If you use star then all columns would be the same width, so you should assign the same SharedSizeGroup to all if you do not mind the auto-sizing aspect:

<Grid.ColumnDefinitions>     <ColumnDefinition Width="Auto" SharedSizeGroup="A"/>     <ColumnDefinition Width="Auto" SharedSizeGroup="B"/>     <ColumnDefinition Width="*" SharedSizeGroup="StarDontWork"/>     <ColumnDefinition Width="Auto" SharedSizeGroup="D"/>     <ColumnDefinition MinWidth="30" Width="*" SharedSizeGroup="StarDontWork"/>     <ColumnDefinition MinWidth="30" Width="*" SharedSizeGroup="StarDontWork"/>     <ColumnDefinition Width="110" SharedSizeGroup="G"/>     <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="H"/>     <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="I"/>     <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="J"/>     <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="K"/>     <ColumnDefinition MinWidth="30" Width="Auto" SharedSizeGroup="L"/> </Grid.ColumnDefinitions> 

(From this behavior it also follows that you can drop the Width property when SharedSizeGroup is set)


You can deduce that if all auto-sizing columns are in shared size groups then all star-sizing columns will have the same sizes as every grid in scope will have the same amount of unused space left that will be distributed to the star-sized columns.

A simple example:

<Grid.ColumnDefinitions>     <ColumnDefinition SharedSizeGroup="A"/>     <ColumnDefinition SharedSizeGroup="B" Width="*"/>     <ColumnDefinition SharedSizeGroup="C"/> </Grid.ColumnDefinitions> 

As explained the Width="*" will not do anything, but as columns 0 and 2 are synched, column 1 has to be synched as well so you can just drop the SharedSizeGroup:

<Grid.ColumnDefinitions>     <ColumnDefinition SharedSizeGroup="A"/>     <ColumnDefinition Width="*"/>     <ColumnDefinition SharedSizeGroup="C"/> </Grid.ColumnDefinitions> 
like image 129
H.B. Avatar answered Sep 29 '22 21:09

H.B.