我得了BindableProperty分,我要考do some stuff when the value changed分. 到目前为止,我得到了这样的结论:
public static readonly BindableProperty IsActiveLinkProperty =
BindableProperty.Create(nameof(IsActiveLink), typeof(bool), typeof(LinkStackLayout), false);
public bool IsActiveLink
{
get => (bool)GetValue(IsActiveLinkProperty);
set => SetValue(IsActiveLinkProperty, value);
}
我读到过关于使用BindingPropertyChangedDelegate到notify changes of my property IsActiveLink的文章,我正在try 实现它.我不能把它写对,我不知道如何写它,它是工作的.如果能得到帮助就太好了.
我最后一次try : (error在第一行,"意想不到的 token ")
BindableProperty.BindingPropertyChangedDelegate<bool>(BindableObject bindable, bool oldValue, bool newValue);
public static readonly BindableProperty IsActiveLinkProperty =
BindableProperty.Create(nameof(IsActiveLink), typeof(bool), typeof(LinkStackLayout), false, BindingMode.TwoWay, propertyChanged: (b, o, n) =>
{
var lsl = (LinkStackLayout)b;
lsl.DoStuff(n);
});
public bool IsActiveLink
{
get => (bool)GetValue(IsActiveLinkProperty);
set => SetValue(IsActiveLinkProperty, value);
}
public void DoStuff()
{
var icon = IsActiveLink ? CursorIconEnum.Hand : CursorIconEnum.Arrow;
this.SetCustomCursor(icon, Handler?.MauiContext);
}