相关疑难解决方法(0)

在Xamarin Forms中登录后更改页面

我有xamarin表单应用程序,具有登录页面.当用户成功登录时,应用程序将导航到MainPageMenu主详细信息页面.我也有同样的问题.这是我在app.cs中的代码:

public App ()
{
    InitializeComponent();
    if (ApplicationSettings.NotLogin()) // Method to check if use if logged in or not
       MainPage = new LoginPage();            
    else            
       MainPage = new NavigationPage(new MainPageMenus());
}
Run Code Online (Sandbox Code Playgroud)

在登录页面中,我写了这段代码:

//Some code for login .....

MasterDetailPage fpm = new MasterDetailPage
{
      Master = new MainPageMenus(),
      Detail = new NavigationPage(new MainPage())
};
Application.Current.MainPage = fpm;
Run Code Online (Sandbox Code Playgroud)

应用程序正确导航到fpm页面,但问题是,当我按下菜单图标时,我得到的详细信息页面不是母版页面.

这个问题类似于一个描述,在此职位.并且上面的代码被选为问题的答案.但代码对我不起作用.在堆栈溢出中,有一个类似的问题,答案是使用这个:

Application.Current.MainPage = new NavigationPage(new MainPageMenus());
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,菜单图标被隐藏.

这是MainPageMenus的Xml:

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"             
                  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"             
                  x:Class="XProject.Menus.MainPageMenus"                                    
                  xmlns:local="clr-namespace:XProject"
                  Title="E-Clinic" …
Run Code Online (Sandbox Code Playgroud)

c# xaml xamarin xamarin.forms

6
推荐指数
1
解决办法
3622
查看次数

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

在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();;
        }


    }
Run Code Online (Sandbox Code Playgroud)

在登录页面

 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)
        { …
Run Code Online (Sandbox Code Playgroud)

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

1
推荐指数
1
解决办法
5330
查看次数