azure - 如何在运行时更改xamarin表单中的MainPage?

标签 azure asp.net-web-api2 azure-mobile-services xamarin.forms

在 xamarin 表单中,RootPage 具有主详细信息布局。我的任务是在用户成功登录后显示该页面。我正在使用 azure 移动服务进行登录。我花了更多的时间来获得结果。我看到了一些其他解决方案,但这些解决方案没有按预期呈现主要细节。最后我得到了解决方案。

这是app.cs中的代码

public App()
    {

     Client = new MobileServiceClient("your azure url", "your master key");
        LoadMainPage();

    } public void LoadMainPage()
    {
        if (Client.CurrentUser == null)
        {
            MainPage=new NavigationPage(new SplashPage());
        }
        else
        {
            MainPage = new RootView();;
        }


    }

在登录页面

 async void  OnLoginClicked(object sender, EventArgs args)
    {
        MobileServiceUser user;

        try
        {
            user = await DependencyService.Get<IMobileClient>().LoginAsync(MobileServiceAuthenticationProvider.Facebook);
            Application.Current.MainPage=new RootView();
            await Navigation.PopToRootAsync();

        }
        catch (InvalidOperationException ex)
        {
            if (ex.Message.Contains("Authentication was cancelled"))
            {
                //messageLabel.Text = "Authentication cancelled by the user";
            }
        }
        catch (Exception ex)
        {
          //  messageLabel.Text = "Authentication failed";
        }

    }

最佳答案

您需要考虑进行导航,而不是更改这些路径的路线。请在此处查看 Xamarin 导航文档:https://developer.xamarin.com/guides/cross-platform/xamarin-forms/getting-started/introduction-to-xamarin-forms/#Navigation

await Navigation.PushModalAsync(new LoginPage());

关于azure - 如何在运行时更改xamarin表单中的MainPage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33137474/

相关文章:

javascript - 使用 flow.js + ng-flow 将文件上传到 WebAPI 2

c# - 如何在 C# ASP.NET Web API 2 中从 Azure 队列返回 HTTP 状态代码

azure - 特定的 TableController 名称不起作用

angularjs - Angular Azure 移动服务客户端 API key 用法

bash - 创建存储帐户后无法立即创建 azure 容器

java - java中的超时值超过启动取消azure函数

c# - GET 请求有效,但 POST 请求在 Web API 2 中为 404

azure - ASP.NET Core Docker 容器内的 Nginx

Azure Databricks - 监视作业集群的启动或关闭状态

azure - 使用适用于 Xamarin Android 的 Azure 移动服务从 Google Api 获取用户信息