每当更改其源属性时,我的表视图都不会更新。代码如下:

public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        viewmodel = this.ViewModel as ListViewModel;
        viewmodel.PropertyChanged += HandlePropertyChangedEventHandler;;
        var source = new MvxSimpleTableViewSource( TableView, LaborCell.Key, LaborCell.Key);
        TableView.Source = source;
        var set = this.CreateBindingSet<ListView, ListViewModel>();
        set.Bind(source).To(vm => vm.LaborTransactions);
        set.Apply();
        TableView.ReloadData();
    }


ViewModel:

        public class ListViewModel :MaxRawBaseViewModel
            {

          public ListViewModel():base()
                {
                    LoadLaborTransactions();
                }

         private Collection<LaborTransaction> _laborTransactions;

                public Collection<LaborTransaction> LaborTransactions
                {
                    get { return _laborTransactions; }
                }

     public void LoadLaborTransactions()
            {
                _laborTransactions = DataService.GetLaborTransactions(somenumber);
                RaisePropertyChanged(() => LaborTransactions);

            }

}


每当Transactions中的更改在propertychanged方法上调用tablview.reolad()时。但是它没有重新加载我的tableview

void HandlePropertyChangedEventHandler(object sender, System.ComponentModel.PropertyChangedEventArgs e){
            if (e.PropertyName.Equals("LaborTransactions"))
            {
                       TableView.ReloadData();
            }
    }

最佳答案

Collection<T>不实现INotifyPropertyChanged。您可以在文档here中进行验证。您需要将LaborTransactions属性更改为实现INotifyPropertyChanged的集合类型,例如ObservableCollection<T>MvxObservableCollection<T>。您可以看到ObservableCollection<T>实现了INotifyPropertyChanged here

更改您的LaborTransactions这样:

private ObservableCollection<LaborTransaction> _laborTransactions;
public ObservableCollection<LaborTransaction> LaborTransactions
{
    get { return _laborTransactions; }
    set {
        return _laborTransactions;
        RaisePropertyChanged(() => LaborTransactions);
    }
}

10-05 20:24
查看更多