ListView's refresh command not working with binded IRelayCommand

2.3k Views Asked by At

I created a form with listview and ISingleOperation fo data refresh.

Then i created command in ViewModel.

 public IRelayCommand LoadInvoicesCommand
    {
        get
        {
            return GetCommand(() => Execution.ViewModelExecute(new LoadInvoicesOperation(_model), 10000));
        }
    }

ISingleOperation works well and returns

new Result() { ResultAction = ResultType.None };

Refresh operation is bound well

RefreshCommand="{Binding LoadInvoicesCommand}"

But refresh indicator "hangs" and not disapearing, what is wrong here?

1

There are 1 best solutions below

0
On BEST ANSWER

You need to bind a second property from the ListView named IsRefreshing to your ViewModel. This is a boolean property and is the one responsible to tell the ListView that the refreshing has started/completed.

An example of a ListView XAML

<ListView 
    VerticalOptions="FillAndExpand"
    IsPullToRefreshEnabled="true"
    RefreshCommand="{Binding LoadInvoicesCommand}"
    IsRefreshing="{Binding IsRefreshing, Mode=OneWay}"
    ItemsSource="{Binding YourItemSource}"
    ItemTemplate="{StaticResource ItemTemplate" />

Your ViewModel will need a public property called IsRefreshing and you will need to set this to false when you the refresh command has completed.