Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attached Property Errors #10652

Closed
david-maw opened this issue Oct 12, 2022 · 3 comments
Closed

Attached Property Errors #10652

david-maw opened this issue Oct 12, 2022 · 3 comments
Labels
area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working

Comments

@david-maw
Copy link

Description

I wanted to migrate a StackPanel containing a CollectionView from Xamarin to MAUI, unfortunately the two are quite different and you have to use a Grid instead of a StackPanel in MAUI. I suggested it would be nice to have a cleaner alternative a (see #10224) and @hartez was kind enough to point me to some sample code that did what I needed, experimenting with this revealed that Attached properties in XAML don't seem to work. It's possible I've missed something, since I've never tried to define an attached property before, but I'm pretty sure I followed the instructions.

Steps to Reproduce

  1. Clone https://github.com/david-maw/MauiAttached.git
  2. Build the project and run it on Windows
  3. Click on one of the txt lines ("Header", "Line 2" or "Footer", then resized the window to see the change in spacing (any hints on how to trigger that redraw automatically gratefully received).
  4. You've now demonstrated it all works, close the program.

Open up MainPage.xaml in Visual Studio, the page content is:

<local:ColumnLayout x:Name="columnLayout">
    <local:ColumnLayout.GestureRecognizers>
        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
    </local:ColumnLayout.GestureRecognizers>
    <Label Text="Header"/>
    <!--<Label Text="Line 1" local:ColumnLayout.Fill="true"/>-->
    <Label x:Name="line2" Text="Line 2"/>
    <Label Text="Footer"/>
</local:ColumnLayout>    

Uncomment the "Line 1" label and intellisense will show an error:

Intellisense

Compile the code and you will see the error:

MainPage.xaml(12,30): XamlC error XFC0020: The name of the BindableProperty Fill does not end with "Property".

On the face of it these would seem to be spurious errors, ColumnLayout.cs begins with:

public class ColumnLayout : VerticalStackLayout
{
    public static readonly BindableProperty FillProperty = BindableProperty.CreateAttached("Fill", typeof(bool),
        typeof(ColumnLayout), false);

Link to public reproduction project repository

https://github.com/david-maw/MauiAttached.git

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

Android 11, Windows 10

Did you find any workaround?

Not for XAML, but the same thing can be done in code as the example demonstrates.

Relevant log output

No response

@david-maw david-maw added the t/bug Something isn't working label Oct 12, 2022
@jsuarezruiz jsuarezruiz added the area-xaml XAML, CSS, Triggers, Behaviors label Oct 13, 2022
@PureWeen
Copy link
Member

@david-maw I think you need to set your GetFill and SetFill to static

@PureWeen PureWeen added the s/needs-info Issue needs more info from the author label Oct 13, 2022
@ghost
Copy link

ghost commented Oct 13, 2022

Hi @david-maw. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@david-maw
Copy link
Author

Thanks @PureWeen that fixed it, sorry, I hadn't realized static Get/Set functions were necessary to create attached properties, thanks for the hint, I'll alert @hartez since it's his code I repurposed to create an attached property instead of a merely bindable one. If anyone's got a hint on how to trigger a control refresh when the property changes dynamically it'd be interesting for the general case but I don't need it for my usage.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants