我正在尝试按如下方式查看加载进度,但它没有显示。
View.cs
fineuploader's accessKey
ViewModel.cs
ViewModel.SelectedCommand.Execute(null);
另一个例子
public ICommand SelectedCommand
{
get
{
return new MvxAsyncCommand(async () =>
{
// the following does not show loading
using (UserDialogs.Instance.Loading("Loading..."))
{
var task = await _classroomService.GetClassRoomAsync(SelectedClassroom.Id);
ObservableCollection<ClassroomViewModel> class = new ObservableCollection<ClassroomViewModel>(task.ConvertAll(x => new ClassViewModel(x)));
}
});
}
}
答案 0 :(得分:1)
如果您使用的是Acr.MvvmCross.Plugins.UserDialogs,请注意它已被删除,您应该直接使用Acr.UserDialogs。
检查您是否已正确初始化它,如下所示:
您必须在PCL项目的App.cs中注册它:
Mvx.RegisterSingleton<IUserDialogs>(() => UserDialogs.Instance);
来自主要活动中的android平台项目的init:
UserDialogs.Init(() => Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity)
要考虑的另一件事是你应该在构造函数中将它作为IUserDialogs
注入(你可以使用静态实例方式,但它增加了更多的灵活性,通过注入它更容易测试):
private readonly IUserDialogs _dialogs;
public ProgressViewModel(IUserDialogs dialogs)
{
this._dialogs = dialogs;
}
并像
一样使用它private async Task RefreshList()
{
using (this._dialogs.Loading("Loading..."))
{
try
{
var task = await this._classService.GetClasses();
}
catch(Exception exc)
{
// This is done only for debugging to check if here lies the problem
throw exc;
}
}
}
您可以通过调用类似
的内容来检查它是否正常工作public ICommand MyTestCommand
{
get
{
return new MvxAsyncCommand(async () =>
{
// the following should should Loading for 3 seconds
using (this._dialogs.Loading("Loading..."))
{
await Task.Delay(TimeSpan.FromSeconds(3));
}
});
}
}
HIH
答案 1 :(得分:0)
我不喜欢这个approuch,但是它有效
Device.BeginInvokeOnMainThread(async () =>
{
try
{
using (UserDialogs.Instance.Loading(("Loading...")))
{
await Task.Delay(300);
await _syncController.SyncData();
//Your Service code
}
}
catch (Exception ex)
{
var val = ex.Message;
UserDialogs.Instance.Alert("Test", val.ToString(), "Ok");
}
});
答案 2 :(得分:0)
您正在使用Loading方法,应使用ShowLoading方法,例如:
UserDialogs.Instance.ShowLoading("Retrieving data...");