【发布时间】:2018-07-20 08:12:55
【问题描述】:
我的列表视图数据在 UWP 和 Android 上正确显示,但在 IOS 上不正确。我认为这与我正在使用的 OnAppearing 方法以及它在 IOS 上实际调用的时间有关。
当我导航到项目列表页面时,从我的仪表板中,ItemPage 后面有以下代码
public ItemPage(string category = null, bool fromDashboard = false)
{
InitializeComponent();
BindingContext = new ItemViewModel(category, fromDashboard);
}
protected override void OnAppearing()
{
var vm = BindingContext as ItemViewModel;
vm?.GetData();
base.OnAppearing();
}
然后在我的ItemViewModel 类中,我有一个构造函数,它接受category 和fromDashboard 标志并设置一些属性。
ItemViewModelGetData() 调用如下:
public void GetData()
{
this.Items = this.RefreshData(this.ItemService.GetAll(this.SelectedCategory));
if (this.FromDashboard)
this.Items = this.Items.Where(x => x.Status != "Complete").ToObservableCollection();
}
最后ItemPage.xaml 有一个ListView 和ItemsSource="{Binding Items}"
由于某种原因,这在 Windows 和 Android 上运行良好,但在 IOS 上不会显示任何数据。页面是在 OnAppearing 方法之前渲染的还是什么?
【问题讨论】:
-
你有没有试过在设置项后在
GetData方法中调用RaisePropertyChanged方法? -
我所有的 ViewModel 都继承自 BaseViewModel,该 BaseViewModel 具有来自 INotifyPropertyChanged 的 OnPropertyChanged 方法。我需要手动调用吗?
-
是的,你需要在某个地方手动调用它。
-
现在将它添加到 GetData 方法的末尾。我会告诉你进展如何。