-
I am trying to create a custom attached property TheWidth: and then refer to it in XAML. Here is my XAML code:
And here is my attached property code:
The compiler complains about it "Unable to resolve suitable regular or attached property TheWidth on type SimpleAvalonTests:SimpleAvalonTests.AttachedProperties What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You are missing generic parameters. public static readonly AttachedProperty<object?> TipProperty =
AvaloniaProperty.RegisterAttached<ToolTip, Control, object?>("Tip"); Here "object?" is the type of value that this property contain. See definition of RegisterAttached method https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/AvaloniaProperty.cs#L267-L287 |
Beta Was this translation helpful? Give feedback.
-
I think you have to define a getter and setter like this: public static double GetTheWidth(AvaloniaObject obj) => obj.GetValue(TheWidthProperty);
public static void SetTheWidth(AvaloniaObject obj, double value) => obj.SetValue(TheWidthProperty, value); |
Beta Was this translation helpful? Give feedback.
I think you have to define a getter and setter like this: