Grid 的 SharedSizeGroup 和 * 大小调整
我有一个用户控件,称为 UserControl
,它有一个带有以下列定义的网格:
<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>
我还有 MainWindow
,它包含一个网格本身,并定义了以下属性在网格上:
Grid.IsSharedSizeScope="True"
现在,我在 MainWindow
中的网格中添加了几个 UserControl(每个控件到一个单独的行)。我的目标是让不同用户控件的每个列宽度保持同步。使用 SharedSizeGroup 时一切正常,除了一件事之外。似乎任何宽度为 *
的列都不会按其应有的方式运行。看起来 *
列宽度被设置为 Auto
。
SharedSizeGroup
和 *
大小调整是否有任何限制/问题?这似乎是保持列宽同步的最佳方法,但我似乎无法解决这个问题。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DefinitionBase.SharedSizeGroup 属性 (Microsoft Docs):
如果您使用星形,那么所有列都将具有相同的宽度,因此如果您不介意自动调整大小方面,则应该为所有列分配相同的
SharedSizeGroup
:(从此行为它还遵循,当设置
SharedSizeGroup
时,您可以删除Width
属性)您可以推断,如果所有自动调整大小的列都在共享大小组中,则所有星号调整列将具有相同的大小,因为范围内的每个网格将具有相同数量的剩余未使用空间,这些空间将分配给星形大小的列。
一个简单的示例:
正如所解释的,
Width="*"
不会执行任何操作,但随着列0
和2
同步,列1
也必须同步,这样您就可以删除SharedSizeGroup
:DefinitionBase.SharedSizeGroup Property (Microsoft Docs):
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:(From this behavior it also follows that you can drop the
Width
property whenSharedSizeGroup
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:
As explained the
Width="*"
will not do anything, but as columns0
and2
are synched, column1
has to be synched as well so you can just drop theSharedSizeGroup
: