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>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…