不允许空的“ColumnDefinitions”和“RowDefinitions”

从 .NET 10 开始,如果<Grid.ColumnDefinitions><Grid.RowDefinitions>在 XAML 中声明但留空,WPF 应用程序将无法生成。 这会导致错误 MC3063,指示属性没有值。

引入的版本

.NET 10

以前的行为

即使在布局定义不完整的情况下,包含空 <Grid.ColumnDefinitions><Grid.RowDefinitions> 的 WPF 应用程序也可以成功编译。 布局默认设置为单行单列,除非另有指定,否则将所有子元素放置在该单个单元格内。

以前编译的示例:

<Grid>
  <Grid.ColumnDefinitions>
  </Grid.ColumnDefinitions>
</Grid>

新行为

从 .NET 10 开始,同一代码现在无法编译,并出现以下错误:

error MC3063: Property 'ColumnDefinitions' does not have a value.

这种情况发生在声明<Grid.ColumnDefinitions><Grid.RowDefinitions>元素时,但这些元素不包含子<ColumnDefinition /><RowDefinition />元素。

破坏性变更的类型

此更改可能会影响 源兼容性

更改原因

此更改是实现 Grid XAML 速记语法支持的直接后果。

确保所有 <Grid.ColumnDefinitions><Grid.RowDefinitions> 中至少包含一个有效的元素。

更正的示例:

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition />
  </Grid.ColumnDefinitions>
</Grid>

受影响的 API

没有。