Xamarin - ListView Displaying Data on IOS

My list views data displays correctly on UWP and Android but not for IOS. I think it has something to do with the OnAppearing method I'm using and when it actually gets called on IOS.

From my Dashboard when I navigate to an Item list page I have the following code behind on the 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();
}

Then in my ItemViewModel class I have a constructor that accepts a category and fromDashboard flag and sets some properties.

The ItemViewModel GetData() call is as follows:

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

And then finally the ItemPage.xaml has a ListView with the ItemsSource="{Binding Items}"

For some reason this works fine on Windows and Android but no data will show on IOS. Is the page being rendered before the OnAppearing method or something?

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai
    edited July 2018

    It seems your Items value has been changed in your GetData() method, have you implemented the INotifyPropertyChanged interface in your viewModel for this Items property? If so, can you debug it on iOS and print the value of Items?

Sign In or Register to comment.