问题
I have this code:
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
Can someone tell me how I can represent this using the new shortcut?
<Grid ColumnDefinitions=" ,50">
In particular I am not sure what to put for the first ColumnDefinition
which in my code is currently just a space before the slash.
Related:
Proposal: Simplify Grid Column and Row Definitions #673
回答1:
As noted on the Grid Docs page the default value for Width
(or Height
in the case of RowDefinitions
) is *
.
The default value of the RowDefinition.Height property is *. Similarly, the default value of the ColumnDefinition.Width property is *. Therefore, it's not necessary to set these properties in cases where these defaults are acceptable.
(from the first "Important" box on the page at the time of writing)
That means, whenever you don't specify the property explicitly, the value is *
. So when you want to use the short-hand notation you would need to use *
回答2:
<ColumnDefinition />
is the equivalent of <ColumnDefinition Width="*" />
.
Using the simplified syntax this would translate to:
<Grid ColumnDefinitions="*, 50">
If you want to be really explicit about it, you can use 1*
instead of *
.
For the complete specs, you can read this: https://github.com/microsoft/microsoft-ui-xaml/issues/673
来源:https://stackoverflow.com/questions/64802635/when-using-the-new-columndefinition-syntax-how-can-i-represent-columndefinitio