【发布时间】:2015-12-16 12:16:29
【问题描述】:
我正在 Xamarin.Forms 中实现一个购物车。在我的购物车页面中有一个带有数据的ListView。每个单元格都包含一个按钮,用于选择item 和amount 的计数。在购物车视图中有一个总计标签。
我的问题是总数没有更新,而数字选择器发生变化。该计算方法在添加视图单元的项目时调用。我知道我需要为此实现INotifyProperty,但我不确定该怎么做。
我有一个基础视图模型,它继承了包含一个事件的 INotifyProperty。
public class BaseViewModel : INotifyPropertyChanged
{
private double _price;
public double Price
{
get
{
return _price;
}
set
{
_price = value;
OnPropertyChanged("Price");}
}
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
查看模型
public BaseViewModel()
{
App.Instance.ViewModel = this;
TempList = TempList ?? new ObservableCollection<cm_items>();
this.Title = AppResources.AppResource.Cart_menu_title;
this.Price = CartCell.price;
}
【问题讨论】:
-
请查看此示例github.com/jamesmontemagno/Hanselman.Forms。在这个存储库中,您可以找到
MVVM模式和INotifyPropertyChanged接口的实现。
标签: c# xamarin xamarin.forms