我有一个BindableProperty,我需要在值更改时做一些事情。到目前为止,我得到了这个:
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来通知我的属性IsActiveLink的更改,我正在尝试实现它。我不能得到它的权利,我不知道如何写它是工作。如果能得到帮助就太好了。
最后一次尝试:(error在第一行,“unexpected 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);
}
1条答案
按热度按时间qvk1mo1f1#
基于你的代码,我会这样做(没有测试,但我假设你知道更多关于你想要什么的信息):