public class UserInventory : INotifyPropertyChanged
{
private int count = 0;
// Declare the event
public event PropertyChangedEventHandler PropertyChanged;
public int Count
{
get => Preferences.Get(nameof(Count),0);
set
{
if (count == value || value <1)
return;
Preferences.Set(nameof(Count), value);
//count = value;
//Application.Current.Properties["Count"] = count;
OnPropertyChanged(nameof(Count));
//OnPropertyChanged(nameof(displayName));
}
}
public UserInventory()
{
}
void OnPropertyChanged(string count)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(count));
}
}
我根据Xamarin <ContentPage.BindingContext>
<local:UserInventory />
</ContentPage.BindingContext>
上的教程在Xaml中添加了此类因此,变量已正确绑定,并且在查看当前页面或推送新页面时没有问题。问题是,当我在iOS上使用“当前库存:35”按钮向后滑动时,前一个屏幕没有更新以反映新的更改。如果我按该屏幕,更改将反映出来。
无论如何,当您返回时是否有界数据更新(PopAsync()?
为了提供一些上下文,我正在编写Xamarin.Forms应用程序,并利用INotifyPropertyChanged与数据绑定。目前,我在一个按钮上显示一个库存计数器。此文本...