gpt4 book ai didi

ios - 当我使用 MvxSimpleTableViewSource 时,xamarin ios Tableview 没有重新加载

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

只要源属性发生更改,我的 TableView 就不会更新。代码如下:

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();
}

View 模型:

        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()。但它没有重新加载我的桌面 View

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);
}
}

关于ios - 当我使用 MvxSimpleTableViewSource 时,xamarin ios Tableview 没有重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57279183/

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