我的代码是
.AXML文件
<MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
local:MvxBind="Refreshing IsBusy;RefreshCommand RefreshCommand">
我的观点模型
private MvxCommand refreshCommand;
public ICommand RefreshCommand
{
get
{
return refreshCommand ?? (refreshCommand = new MvxCommand(ExecuteRefreshCommand));
}
}
private bool m_IsBusy;
public new bool IsBusy
{
get { return m_IsBusy; }
set
{
m_IsBusy = value; RaisePropertyChanged(() => IsBusy);
BaseMessage = m_IsBusy ? "Refreshing..." : string.Empty;
}
}
async private void ExecuteRefreshCommand()
{
await Task.Run(() => { m_IsBusy = false; });
}
我能够看到加载器,加载器无限加载,但无法停止刷卡刷新加载器。
看看code的MvxSwipeRefreshLayout
你可以看到它继承自SwipeRefreshLayout
。 SwipeRefreshLayout
包含一个布尔Refreshing
。这表明它正在加载,因此应显示加载图标。将此设置为false将隐藏动画。
您可以通过绑定它来完成此操作。在ViewModel中创建一个额外的属性,例如isRefreshing
,如:
private bool _isRefreshing;
public bool IsRefreshing
{
get { return _isRefreshing; }
set
{
_isRefreshing = value;
RaisePropertyChanged(() => IsRefreshing);
}
}
现在在你的视图中绑定实际绑定两个像:
<MvxSwipeRefreshLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
local:MvxBind="Refreshing IsRefreshing; RefreshCommand RefreshCommand">
现在,您必须在“刷新工作”完成后手动将布尔值设置为false。例如:
public IMvxCommand RefreshCommand
{
get
{
return new MvxCommand(async () => {
// This simulates some refresh work which takes 3 seconds
await Task.Delay(3000);
IsRefreshing = false;
});
}
}