New with 4.7 - Looking for a way to specify RowDefinitions="1*, Auto, 25, 14, 20" in C#

Viewed 80

Given this Row Definition;

<Grid RowDefinitions="1*, Auto, 25, 14, 20">
    ...
</Grid>

Does anyone know how I can specify this in C# now that it's a feature of Xamarin.Forms 4.7

1 Answers

Unfortunately, no. As per Grid's documentation for Simplify row and column definitions:

In XAML, the row and column characteristics of a Grid can be specified using a simplified syntax that avoids having to define RowDefinition and ColumnDefinition objects for each row and column.

The important part is the first 2 words - in XAML.

I dug a bit deeper into this and it turned out that indeed the feature is XAML-only, at least for now. From the official pull request we can see that the functionality is being implemented via a couple of TypeConverters. From the commit that implements the new flow we can look into the ColumnDefinitionCollectionTypeConverter.cs and see on the fifth line that the converter is for XAML only:

[Xaml.TypeConversion(typeof(ColumnDefinitionCollection))]

To sum up - no, for now the feature is XAML-only. But, because of the upcoming MAUI, we are seeing more and more of the feature coming as C# extensions, so I assume it is just a matter of time to see this coming to C# as well.

You can read more about TypeConverters in XAML here.

Related