【问题标题】:How to display a confirmation dialog before splash screen is closed in Xamarin Forms如何在 Xamarin Forms 中关闭初始屏幕之前显示确认对话框
【发布时间】: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 包显示确认对话框,但由于库尝试将视图附加到导航堆栈,而出现错误,此时导航堆栈尚未初始化。

感谢您对此的帮助

【问题讨论】:

标签: xamarin.forms xamarin.android xamarin.ios mvvmcross


【解决方案1】:

您可以允许加载应用程序并创建一个名为 StartupPage 的新页面,该页面具有与 SplashScreen 相似的背景。在该页面上,您可以显示 ConfirmationPopup。如果验证正确,您可以将用户导航到第一页,或者您可以关闭应用程序或关闭确认页面,用户将在 Splashscreen 背景启动页面上。

我想您将无法在 SplashScreen 上或在您的应用启动之前显示确认对话框。

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 1970-01-01
    • 2016-03-24
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 2020-12-12
    相关资源
    最近更新 更多