|
| 1 | +--- |
| 2 | +title: "Breaking change - WPF throws MC3063 error for empty ColumnDefinitions or RowDefinitions" |
| 3 | +description: "Learn about the breaking change in .NET 10 where empty Grid.ColumnDefinitions or Grid.RowDefinitions declarations now cause MC3063 compilation errors." |
| 4 | +ms.date: 01/27/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs/issues/47743 |
| 7 | +--- |
| 8 | + |
| 9 | +# WPF throws MC3063 error for empty ColumnDefinitions or RowDefinitions |
| 10 | + |
| 11 | +Starting with .NET 10 Preview 5, WPF applications fail to build if `<Grid.ColumnDefinitions>` or `<Grid.RowDefinitions>` are declared but left empty in XAML. This results in error **MC3063**, indicating that the property doesn't have a value. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET 10 Preview 5 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +WPF applications with empty `<Grid.ColumnDefinitions>` or `<Grid.RowDefinitions>` compiled successfully, even though the layout definitions were incomplete. WPF would default to a single row and column, placing all child elements in that single cell unless otherwise specified. |
| 20 | + |
| 21 | +Example that previously compiled: |
| 22 | + |
| 23 | +```xml |
| 24 | +<Grid> |
| 25 | + <Grid.ColumnDefinitions> |
| 26 | + </Grid.ColumnDefinitions> |
| 27 | + <Grid.RowDefinitions> |
| 28 | + </Grid.RowDefinitions> |
| 29 | + <TextBlock Text="Hello World" /> |
| 30 | +</Grid> |
| 31 | +``` |
| 32 | + |
| 33 | +## New behavior |
| 34 | + |
| 35 | +The same code now fails to compile with the following error: |
| 36 | + |
| 37 | +```output |
| 38 | +error MC3063: Property 'ColumnDefinitions' does not have a value. |
| 39 | +error MC3063: Property 'RowDefinitions' does not have a value. |
| 40 | +``` |
| 41 | + |
| 42 | +This occurs when `<Grid.ColumnDefinitions>` or `<Grid.RowDefinitions>` elements are declared but contain no child `<ColumnDefinition />` or `<RowDefinition />` elements. |
| 43 | + |
| 44 | +## Type of breaking change |
| 45 | + |
| 46 | +This is a [source-incompatible](../../categories.md#source-compatibility) change. |
| 47 | + |
| 48 | +## Reason for change |
| 49 | + |
| 50 | +This change is a direct consequence of implementing Grid XAML Shorthand Syntax support. The enhancement improves XAML parsing by being more strict about property declarations that don't contain meaningful content. |
| 51 | + |
| 52 | +## Recommended action |
| 53 | + |
| 54 | +Choose one of the following approaches to resolve the compilation error: |
| 55 | + |
| 56 | +### Option 1: Remove empty declarations |
| 57 | + |
| 58 | +Remove the empty `<Grid.ColumnDefinitions>` and `<Grid.RowDefinitions>` elements entirely: |
| 59 | + |
| 60 | +```xml |
| 61 | +<Grid> |
| 62 | + <TextBlock Text="Hello World" /> |
| 63 | +</Grid> |
| 64 | +``` |
| 65 | + |
| 66 | +### Option 2: Add actual definitions |
| 67 | + |
| 68 | +If you need specific column or row definitions, add the appropriate `<ColumnDefinition />` or `<RowDefinition />` elements: |
| 69 | + |
| 70 | +```xml |
| 71 | +<Grid> |
| 72 | + <Grid.ColumnDefinitions> |
| 73 | + <ColumnDefinition /> |
| 74 | + </Grid.ColumnDefinitions> |
| 75 | + <Grid.RowDefinitions> |
| 76 | + <RowDefinition /> |
| 77 | + </Grid.RowDefinitions> |
| 78 | + <TextBlock Text="Hello World" /> |
| 79 | +</Grid> |
| 80 | +``` |
| 81 | + |
| 82 | +## Affected APIs |
| 83 | + |
| 84 | +None. |
0 commit comments