gpt4 book ai didi

c# - 将值绑定(bind)到 Xamarin 中 View 的扩展

转载 作者:行者123 更新时间:2023-11-29 05:17:25 24 4
gpt4 key购买 nike

我试图将列表中的整数值链接到 StackLayout 的扩展值“Index”。无论我尝试做什么,尽管将所有数据设置为“7”(随机),但该值始终最终为 0。

扩展代码如下:

 public class NamedStackLayout : StackLayout
{
public string Name { get; set; }
public int Index { get; set; }

public static readonly BindableProperty IndexProperty = BindableProperty.Create("Index", typeof(int), typeof(NamedStackLayout), 1);

public int IndexValue
{
get { return (int)GetValue(IndexProperty); }
set { SetValue(IndexProperty, value); }
}
}

最佳答案

您需要实现 INotifyPropertyChanged

并重写此方法

protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}

之后在 IndexValue 的 setter 中调用 OnPropertyChanged

关于c# - 将值绑定(bind)到 Xamarin 中 View 的扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59053246/

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