【问题标题】:MvvmCross.Forms - Default Spinner will not exitMvvmCross.Forms - 默认 Spinner 不会退出
【发布时间】:2021-04-06 15:25:00
【问题描述】:

此错误存在于示例文件 (StarWarsSample) 中,我已尝试将其删除几个小时...感谢任何建议:

使用 MvvmCross.Forms

我有一个将 RefreshCommand 绑定到命令的 MvxListView。我已经确认它会着火。当 MvxListView 被拉下 (iOS 和 Android) 时,会出现一个微调器。然而它永远不会消失。我没有抛出任何异常。如果我提出一个对话框,它会出现在微调器上,但是一旦取消,微调器就会保留。我的 ListView 动态更新正常。只是微调器永远不会消失......我假设它来自 MVVMCross/Forms 中的某个特定函数,但我似乎找不到任何对它的引用。

这是相关代码(在尝试不同方法后处于当前状态)

 <views:MvxListView 
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand"
            SelectionMode="None"
            ItemsSource="{mvx:MvxBind BtDevices}" 
            ItemClick="{mvx:MvxBind BtDeviceSelectedCommand}"
            IsPullToRefreshEnabled="True" 
            RefreshCommand="{mvx:MvxBind RefreshBtDevicesCommand}"
            ItemTemplate="{StaticResource DeviceNameTemplate}"
            RowHeight="{x:OnPlatform Android=55, iOS=55, UWP=40}"
            BackgroundColor="LightBlue"
            SeparatorVisibility="None">
           
        </views:MvxListView>

 public HomeViewModel(...){
BtDevices = new MvxObservableCollection<BtDevice>();

        BtDeviceSelectedCommand = new MvxAsyncCommand<IBtDevice>(BtDeviceSelected);
        FetchBtDevicesCommand = new MvxCommand(() =>
        { 
            FetchBtDeviceTask = MvxNotifyTask.Create(LoadDevices, onException: OnException);
            RaisePropertyChanged(() => FetchBtDeviceTask);
        });

        RefreshBtDevicesCommand = new MvxCommand(()=>
        {
            RefreshDeviceTask = MvxNotifyTask.Create(RefreshBtDevices, OnException);
            RaisePropertyChanged(() => RefreshDeviceTask);
        });
}
 private async Task RefreshBtDevices()
    {
        IsBusy = true;
        var result = await _btService.LoadDevices(_nextPage);

        foreach (var d in result.Where(d => BtDevices.FirstOrDefault(i => i.Id == d.Id) == null))
        {
            BtDevices.Add(d);
        }

        IsBusy = false;

        await RaisePropertyChanged(() => RefreshDeviceTask);
        await RaisePropertyChanged(() => RefreshBtDevicesCommand);
        
    }

【问题讨论】:

  • 忘了说 MvvmCross 和 MvvmCross.Forms V7.1.2(最新稳定版)
  • 好的..所以我只是注意到我使用的是 MvxCommand 而不是 MvxAsyncCommand。我改变了...但是,现在微调器立即消失,列表视图不会第二次刷新...

标签: xamarin.forms mvvmcross mvxlistview


【解决方案1】:

您需要从docs 绑定列表视图的IsRefreshing 属性。

获取或设置一个表明列表视图当前是否正在刷新的值

类似这样的:

IsRefreshing="{mvx:MvxBind IsBusy}"

或者如果您使用的是MvxNotifyTask

IsRefreshing="{mvx:MvxBind RefreshDeviceTask.IsNotCompleted}"

Here 你有更多信息,即使它在示例中直接使用ListView,同样可以应用于MvxListView,因为它继承自ListView

【讨论】:

  • 谢谢,我不知道为什么直到现在我才收到通知!我放弃了样本并制定了不同的方法。如果我无法确认这是答案,我不知道协议,因为我无法测试它......我很欣赏你的回复,很抱歉我之前没有看到这个!
猜你喜欢
  • 2015-11-28
  • 1970-01-01
  • 1970-01-01
  • 2014-01-29
  • 1970-01-01
  • 1970-01-01
  • 2018-04-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多