【发布时间】: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