2
votes

I am using mvvmcross (with great fun) but I keep having problems with adding and removing items from mvxlistview:

My View is binded to a List of items which are retrieved from a web server so it is done in a different thread:

async void  ActivateSearchInvoked ()
    {
        _activeSearchViewModel.IsLoading = true;
        await _activeSearchViewModel.Search (SearchString);
        _activeSearchViewModel.IsLoading = false;
    }   

Search is a method which calls InnerSearch, Here is the code in the View Model

protected override Task InnerSearch ()
    {
        Users.Clear ();
        return Task.Factory.StartNew (SearchForUsers);
    }

    protected virtual void SearchForUsers()
    {
        int requestringUserID = AppConfiguration.Instance.User.ID;
        List<User> users = GetUsersFromWeb();
        if(users == null)
        {
            return;
        }
        foreach (var item in users)
        {
            Users.Add (new UserViewModel (item));
        }
        RaisePropertyChanged (() => Users);
    }

This does not seem to work properly until the screen is refreshed (for instance rotating it) Am I missing something?

Thanks

Amit

1
Not sure. But I think RaisePropertyChanged needs to be done on the UI thread, I can't remember if the method does that internally, but try wrap it yourself. - Cheesebaron

1 Answers

3
votes

Unless you are actually using a different source List or an INotifyCollectionChanged supporting collection, then the MvxAdapter will receive your change notification - but will not actually know it has any work to do.

In order to work around this, either: