如何在毛伊岛使用 DependencyProperty?

ana*_*and 3 c# maui .net-6.0

我正在尝试在毛伊岛使用依赖属性,但它似乎不适用于毛伊岛。它显示参考缺失错误。我该如何解决?相同的代码在 xamarin 和 uwp 中工作,但在毛伊岛它显示 DependencyProperty 关键字的引用错误。

以下是代码示例:

  public static CornerRadius GetCornerRadius(Button element)
    {
        return (CornerRadius)element.GetValue(CornerRadiusProperty);
    }

    public static readonly DependencyProperty CornerRadiusProperty =
        DependencyProperty.RegisterAttached(
            "CornerRadius",
            typeof(CornerRadius),
            typeof(ButtonHelperClass),
            new PropertyMetadata(new CornerRadius(5))
            );
Run Code Online (Sandbox Code Playgroud)

ana*_*and 7

我们可以使用 BindableProperty 代替 DependencyProperty

public static CornerRadius GetCornerRadius(Button element)
{
    return (CornerRadius)element.GetValue(CornerRadiusProperty);
}

public static readonly BindableProperty CornerRadiusProperty =
    BindableProperty.CreateAttached(
        "CornerRadius",
        typeof(CornerRadius),
        typeof(ButtonHelperClass),
        new CornerRadius(5)
        );
Run Code Online (Sandbox Code Playgroud)