gpt4 book ai didi

xamarin.forms - 如何获取 BindableProperty 的值?

转载 作者:行者123 更新时间:2023-12-04 04:15:15 24 4
gpt4 key购买 nike

我想获得 BindableProperty 的值,因为我希望我的 BindableProperty 有两个状态,因为我可以区分

<local:MyEntry event="{Binding Flag,  Mode=TwoWay}">

在我的自定义条目中:
    public static  BindableProperty EventProperty =
BindableProperty.Create("event", typeof(string), typeof(MyEntry), "sigle", propertyChanged: (obj, oldValue, newValue) =>
{ });
private string flag;
public string Flag
{
get { return flag; }
set
{
if (flag != value)
{
flag = value;
NotifyPropertyChanged("event");
}
}
}

在我的 viewModel 中,这是代码:
private string flag;
public string Flag
{
get { return flag; }
set
{
if (flag != value)
{
flag = value;
RaisePropertyChanged(() => Flag);
}
}
}
private async Task Execute()
{
Flag = "Change";
}

在我的自定义渲染器中
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
Console.WriteLine("HERE "+ (entry as MyEntry).Flag);
//here i want to get the value

在回答 的帮助下
if (e.PropertyName == MyEntry.EventProperty.PropertyName)
{
var entry = Element as MyEntry;
var Flag = entry.Flag;
Console.WriteLine("... "+ Flag);

最佳答案

在自定义渲染器中

 public static BindableProperty FlagProperty = BindableProperty.Create("Flag", typeof(string), typeof(MyEntry), string.Empty, propertyChanged: (obj, oldValue, newValue) =>
{
var entry = obj as MyEntry;
entry.Flag = newValue.ToString();
});
private string flag;
public string Flag
{
get { return flag; }
set
{
if (flag != value)
{
flag = value;
NotifyPropertyChanged("Flag");
}
}
}

在自定义渲染器中
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);

if (e.PropertyName == MyEntry.EventProperty.PropertyName)
{
// will been invoked when the value changed
var entry = Element as MyEntry;
var Flag = entry.Flag;
}


}

关于xamarin.forms - 如何获取 BindableProperty 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60823452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com