Skip to content

Conversation

@ne0rrmatrix
Copy link
Member

@ne0rrmatrix ne0rrmatrix commented Dec 22, 2025

Description of Change

Add support for Attached Bindable Properties so that we can update and merge #3016 #3000

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard

Additional information

This add support for both CreateAttached and Readonly support. Link to documentation for Attached Properties https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/attached-properties?view=net-maui-10.0

@TheCodeTraveler
Copy link
Collaborator

TheCodeTraveler commented Dec 22, 2025

Hey James! It looks like you don't have an in-depth understanding on Attached Bindable Properties.

They are a BindableProperty that don't have an associated public property. Instead, they are accessed via static methods.

From from the docs:

...attached properties enable an object to assign a value for a property that its own class doesn't define

Here's an example from the docs:

public class MyControl
{
    public static readonly BindableProperty HasShadowProperty =
        BindableProperty.CreateAttached("HasShadow", typeof(bool), typeof(MyControl), false);

    public static bool GetHasShadow(BindableObject view)
    {
        return (bool)view.GetValue (HasShadowProperty);
    }

    public static void SetHasShadow(BindableObject view, bool value)
    {
        view.SetValue(HasShadowProperty, value);
    } 

}

Therefore, we won't be placing [AttachedBindableProperty] on a property.

Options For [AttachedBindableProperty]

1. Attribute on Class

We can place the attribute on the class:

[AttachedBindableProperty<bool>(PropertyName="HasShadow", DefaultValue = false, BindingMode = BindingMode.OneWay, ValidateValueMethodName = null, PropertyChangedMethodName = null, PropertyChangingMethodName = null, CoerceValueMethodName = null, DefaultValueCreatorMethodName = null)]
public partial class MyCustomView
{
}

2. Attribute on Constructor

We can place the attribute on the constructor

public partial class MyCustomView
{
    [AttachedBindableProperty<bool>(PropertyName="HasShadow", DefaultValue = false, BindingMode = BindingMode.OneWay, ValidateValueMethodName = null, PropertyChangedMethodName = null, PropertyChangingMethodName = null, CoerceValueMethodName = null, DefaultValueCreatorMethodName = null)]
    public class MyCustomView()
    {

    }
}

You've clearly invested a lot of time into this. I highly recommend you do more research on Attached BindableProperty to understand their use and look at examples of how developers use them before devoting more time towards writing this source generator:

https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/attached-properties?view=net-maui-10.0

https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.bindableproperty.createattached?view=net-maui-10.0

@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants