【发布时间】:2020-01-23 11:39:27
【问题描述】:
我正在使用面向 Android 和 iOS 的 MVVMCross 开发 Xamarin.Forms 应用程序,现在我需要在应用程序完全加载之前在服务器上执行一些验证,这些验证的结果我需要显示一个确认对话框向用户发送消息并阻止他在接受或取消对话之前继续。
这是我需要工作的模拟代码:
public class App : MvxApplication
{
public override void Initialize()
{
//... a lot of Dependencies registering
RegisterCustomAppStart<AppStart>();
}
}
public class AppStart : MvxAppStart
{
private readonly IMvxLog _log;
private readonly IMyApiService _apiService;
public AppStart(IMvxApplication application, IMvxNavigationService navigationService) : base(application, avigationService)
{
_log = Mvx.IoCProvider.Resolve<IMvxLog>();
_apiService = Mvx.IoCProvider.Resolve<IMyApiService>();
}
protected override Task NavigateToFirstViewModel(object hint = null)
{
//This is all the code I need to make work, all these lines are pseudo code
//Do my server side validations
var myObj = await _apiService.staticValidations();
//Here I need to validate myObj, something like:
var result = false;
if(myObj.boolValue)
{
var result = await showConfirmationDialog();
//result should contains the value depending on user's selection: if pressed cancel or ok button
}
//At this point the splashscreen must continue freezed
if(result)
{
var mvxBundle = new MvxBundle(new Dictionary<string, string> {{BaseViewModel.NavigationBarParameter, "false"}});
await navigation.Navigate(myMainViewModel, mvxBundle);
}
else
{
//Other things
}
}
}
我尝试使用一些 nuget 包显示确认对话框,但由于库尝试将视图附加到导航堆栈,而出现错误,此时导航堆栈尚未初始化。
感谢您对此的帮助
【问题讨论】:
-
你也可以使用DependencyService在 OnStart() 方法中调用原生对话框
标签: xamarin.forms xamarin.android xamarin.ios mvvmcross