Extending a UI element without subclassing using attached properties
Have you ever used extension methods in C#?
public class ClassA { //... } public static class ClassAExtensions { public static void MethodX(this ClassA a) { //... } } //… ClassA classA = new ClassA(); classA.MethodX();
This is a great concept that helps you extend the functionality of a certain class without creating a descendant. In .NET MAUI, you can create not only methods but also extensions or attached properties for UI elements without subclassing them. Even if you haven’t created custom attached properties yet, I’m sure you’ve already used them in the Grid
panel:
<Grid ColumnDefinitions="*,*" RowDefinitions="*,*"> <Label Grid.Row="1" Grid.Column="1"/> </Grid>
Here, Grid.Row...