XAML ColumnDefinition 中 *(星号)的含义是什么?
下面的 XAML 中 *(星号)的含义是什么?
<ColumnDefinition Width="0.07*"/>
<Grid Height="100" HorizontalAlignment="Left"
Margin="102,134,0,0"
Name="grid1" VerticalAlignment="Top"
Width="354">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40*" />
<ColumnDefinition Width="314*" />
</Grid.ColumnDefinitions>
</Grid>
What is the meaning of * (asterisk) in the XAML below?
<ColumnDefinition Width="0.07*"/>
<Grid Height="100" HorizontalAlignment="Left"
Margin="102,134,0,0"
Name="grid1" VerticalAlignment="Top"
Width="354">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40*" />
<ColumnDefinition Width="314*" />
</Grid.ColumnDefinitions>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您在 WPF 网格中定义列时,您可以将宽度设置为三个可能值之一:
自动
– 列将根据需要变得足够宽以适合其子项,或者*
(星号)占用任何可用的剩余空间*
以数字为前缀(如果未指定数字,则默认为 1)。可用空间按照前缀编号的比例在加星标的列之间分配。如果您有此定义,
则第一列将获得可用总空间的 7%,第二列将获得 93%。另一方面,如果您有这样的定义:
第一列将获得 1/3 的可用空间,第二列将获得 2/3 的可用空间。
在网格宽度为 354 且两列的比例为 40 和 314 的特定情况下,您将获得以下列宽度:
当网格宽度不固定时,最好使用星形宽度。当网格大小调整时,列将按照星形宽度指定的比例缩放。在您的情况下,网格的宽度是固定的,您可以轻松地使用固定宽度的列。
如果您想要一个布局,其中第二列的宽度是第一列的两倍,第三列的宽度是第一列的三倍,您需要以下定义:
如果网格的总宽度为 300,则列宽为 50、100 和 150如果网格的总宽度为 600,则列宽为 100、200 和 300。依此类推。
When you define a column in a WPF grid you can set the width to one of three possible values:
Auto
– column will become as wide as necessary to fit its children, or*
(star) take up any available remaining spaceThe
*
is prefixed by a number (default is 1 if no number is specified). The available space is divided among the starred columns in proportion to the prefix number.If you have this definition
The first column will get 7% of the total space available and the second column would get 93%. On the other hand if you had this definition:
The first column would get 1/3 and the second 2/3 of the available space.
In your specific case where the width of the grid is 354 and the proportions of the two columns are 40 and 314 you get the following column widths:
The star width is best used when the width of the grid isn't fixed. When the grid is resized the columns will then scale proportionally as specified by the star widths. In your case the width of the grid is fixed and you could just as easily have used fixed width columns.
If you want a layout where the second column is double the width of the first and the third column is triple the width of the first you need this definition:
If the total width of the grid is 300 you get column widths 50, 100 and 150. If the total width of the grid is 600 you get column widths 100, 200 and 300. And so on.
它与任何其他星形宽度列的比率为 0.07 - 即,如果另一个 ColomnDefinition 的宽度为 0.14,则该列是宽度的两倍 = 其全部与配给有关
Its 0.07 ratio to any other star-width column - i.e. if another ColomnDefinition has a Width of 0.14 then that column is double the width = its all about rations
它使用比率创建列大小。如果您有另一个定义,例如
,第一列将占用 70% 的空间,第二列将占用 30%。It creates column sizes using ratios. If you had another definition like
<ColumnDefinition Width="0.03*"/>
the first column would take up 70% of space and the second one would take up 30%.