如何覆盖Xamarin模板中的属性?

时间:2019-12-26 16:35:41

标签: xamarin xamarin.forms

我有此代码:

public class GST45Button : GButton
{
    public GST45Button()
    {
        WidthRequest = 45;
    }

    public static BindableProperty IsDisabledProperty =
  BindableProperty.Create(nameof(IsDisabled), typeof(bool), typeof(GST45Button), default(bool), propertyChanged: IsDisabledPropertyPropertyChanged);

    public bool IsDisabled
    {
        get { return (bool)GetValue(IsDisabledProperty); }
        set { SetValue(IsDisabledProperty, value); }
    }

    private static void IsDisabledPropertyPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        if ((bool)newValue)
        {
            GST45Button gST45 = bindable as GST45Button;
            gST45.IsEnabled = false;
            gST45.Opacity = 0.5;
        }
        else
        {
            GST45Button gST45 = bindable as GST45Button;
            gST45.IsEnabled = true;
            gST45.Opacity = 1;
        }
    }
}

GButton还具有IsDisabledProperty,并且IDE正在给出一条消息,提示:

enter image description here

有人可以告诉我如何在此处添加“新”属性来解决此警告。

请注意,在这种情况下,“显示潜在的修复程序”仅允许我隐藏或支持错误。它没有建议如何使用“新”修复它。

0 个答案:

没有答案