0

I'm pretty new to .NET

In .NET MAUI 9.0 I am creating an app based on a custom Layout extending the Grid class, which uses several BindingProperties that i have no issues with:

namespace krizanke_ux.Resources.LayoutResources
{
    public partial class ParametricGrid : Grid
    {
        public static readonly BindableProperty GridWidthProperty =
            BindableProperty.Create(nameof(GridWidth), typeof(double), typeof(ParametricGrid), 10.0,
                propertyChanged: (b, o, n) => ((ParametricGrid)b).RebuildGrid(),
                validateValue: (b, value) => (double)value >= 0.0);

I've now started implementing attached properties for the Grid's children, which raise the following error: XC0009: No property, BindableProperty, or event found for "GridHorizontalAlignment", or mismatching type between value and property.

Here is the appropriate code:

private static readonly BindableProperty GridHorizontalAlignmentProperty =
    BindableProperty.CreateAttached("GridHorizontalAlignment", 
        typeof(LayoutAlignment), typeof(ParametricGrid), LayoutAlignment.Start);

public static LayoutAlignment GetGridHorizontalAlignment(BindableObject view) =>
    (LayoutAlignment)view.GetValue(GridHorizontalAlignmentProperty);
public static void SetGridHorizontalAlignment(BindableObject view, LayoutAlignment value) =>
    view.SetValue(GridHorizontalAlignmentProperty, value);
<ContentPage ...
             xmlns:layout="clr-namespace:krizanke_ux.Resources.LayoutResources"...>
<layout:ParametricGrid ...>

<Entry
    Grid.Row="5"
    layout:ParametricGrid.GridHorizontalAlignment="Center"
    Grid.RowSpan="4"
    Grid.ColumnSpan="7"/>

I cannot find the solution anywhere. I've tried using both LayoutOptions and LayoutAlignment, using GridHorizontalAlignmen="{x:Static LayoutAlignment.Center}" even though Visual Studio automatically suggests "Center" in XAML.

2
  • 1
    What happens when you declare GridHorizontalAlignmentProperty public? Commented Sep 15 at 8:42
  • @Clemens, It works when the BindableProperty is public. I feel very dumb, because i triple checked every single letter, but did not bother to check the beginning. Thank you. Commented Sep 15 at 16:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.