When using the new ColumnDefinition syntax, how can I represent <ColumnDefinition />

萝らか妹 提交于 2021-01-05 09:12:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!