ListView 的刷新命令不适用于绑定的 IRelayCommand



我创建了一个带有listView和isingleoperation fo数据刷新的表单。

然后我在ViewModel中创建了命令。

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

isingleoperation效果很好,返回

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

刷新操作的绑定良好

RefreshCommand="{Binding LoadInvoicesCommand}"

但刷新指示器"悬挂"而不拆除,这里有什么问题?

您需要将第二个属性从 ListView绑定到命名为iSrefreshing到您的ViewModel。这是一个布尔属性,是负责告诉ListView的人。

listView xaml

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

您的ViewModel将需要一个称为IsRefreshing的公共属性,当您完成刷新命令时,您需要将其设置为false

最新更新