Property Is Never Updated after Task Completes

Goobs1284Goobs1284 USMember ✭✭

I have a list view that has it's IsRefreshing property binding back to a viewmodel's IsBusy property; side note i am going for an MVVM approach. The issue is this, when IsBusy is set to false, it never removes the spinning circle on the list view and it's as if the property never changes. The IsBusy property is set something like this:

    public async void Set()
    {
        try
        {
            IsBusy = true;
            List<Item> getItems = await service.GetItems();

                //SETTING LISTS

            selectedItem = null;
            searchString = string.Empty;

            IsBusy = false;
        }
        catch (Exception a)
        {
            //log it
            IsBusy = false;
        }
    }

The Set() function is being called within a page load commnad. Originally, this try/catch block was in the page load command, but tried this route as the IsBusy property never seemed to stop the listview from showing the spinning circle. I do know that this viewmodel is hooked up correctly to the view as the commands and other properties do work as they should.

    private bool _IsBusy;
    public bool IsBusy
    {
        get { return _IsBusy; }
        set { Set("IsBusy", ref _IsBusy, value); }
    }

And that is the property.

    <ListView ItemsSource="{Binding items}"
                      RefreshCommand="{Binding LoadItemsCommand}"
                      IsPullToRefreshEnabled="true"
                      SelectedItem="{Binding selectedItem}"
                      IsRefreshing="{Binding IsBusy}"
                      Style="{StaticResource listViewStyle}">
            <!-- OTHER STUFF -->
    </ListView>

And that's the view

Answers

  • JesusAntonJesusAnton USMember ✭✭
    edited August 2017

    tienes que agregarle INotifyPropertyChanged a la clase:
    luego modificas y agregas el OnPropertyChanged();

    private bool _IsBusy;
    public bool IsBusy
    {
    get
    {
    return _IsBusy;
    }
    set
    {
    _IsBusy = value;
    OnPropertyChanged();
    }
    }

    y el tu XAML:



  • Goobs1284Goobs1284 USMember ✭✭

    @JesusAnton The Set("IsBusy", ref _IsBusy, value) line automatically throws OnPropertyChanged(); via MVVMLight

  • JesusAntonJesusAnton USMember ✭✭

    usa eso

Sign In or Register to comment.