简体   繁体   English

如何从CarouselPage导航到MasterDetailPage

[英]How to navigate from CarouselPage to MasterDetailPage

I have to navigate from CarouselPage to MasterDetailPage. 我必须从CarouselPage导航到MasterDetailPage。 I have created two different my first page is carousel page on click of any button in curousel page i should navigate to masterdeatilpage. 我创建了两个不同的页面,单击“转盘”页面中的任何按钮后,我的第一页是“转盘”页面,我应该导航到masterdeatilpage。

Please help me out how to write the code and my master page is different and detail page is differnet both is written in content page. 请帮我写代码,我的母版页和细节页是不同的,两者都写在内容页中。

code: 码:

app.cs app.cs

public static MasterDetailPage MasterDetailPage;
public App()
{
    var isLoggedIn = App.Current.Properties.ContainsKey("IsLoggedIn")? (bool)Properties["IsLoggedIn"] : false;
        // The root page of your application
        if (isLoggedIn)
        {
            MasterDetailPage = new Xamarin.Forms.MasterDetailPage
            {
                Master = new Menu(),
                Detail = new NavigationPage(new detail())
                {
                    Tint = Color.FromHex("313FA0")
                }
            };

            MasterDetailPage.MasterBehavior = MasterBehavior.Popover;

            MainPage = MasterDetailPage;
        }
        else
        {
           MainPage = new NavigationPage(new carousel());
        }
}

carousel.xaml.cs carousel.xaml.cs

<CarouselPage>
 <ContentPage>
   <StackLayout>
     <Button Text="click" Clicked="funca()"/>
   </StackLayout>
  </ContentPage>
</CarouselPage>

carousel.cs carousel.cs

void funca(object sender, EventArgs e){
    App.MasterDetailPage.Master = new Menu();
    App.MasterDetailPage.Detail = new NavigationPage(new detail());
    App.MasterDetailPage.IsPresented = false;  
}

In Click of the button it is shown error 在按钮的单击中显示错误

System.Exception: Object reference not set to an instance of an object

Please help me out 请帮帮我

Please have a look at my sample repo here . 请在这里查看我的样本回购。 I am using there solution based on MessagingCenter I believe it should also work in your scenario. 我使用基于解决方案MessagingCenter我相信它也应该在你的情况下工作。 Remember to put something similar to this in your MasterDetailPage . 记得把类似的东西MasterDetailPage

I found the answer of the given question with help of @Tomasz Kowalczyk thanks dude 我在@Tomasz Kowalczyk的帮助下找到了给定问题的答案,谢谢dude

I created one class MasterPage.cs 我创建了一个类MasterPage.cs

public class MasterPage : MasterDetailPage
{
    public MasterPage()
    {
        Master = new Menu();
        Detail = new NavigationPage(new detail());
    }
}

app.cs app.cs

public App()
{
  var isLoggedIn = App.Current.Properties.ContainsKey("IsLoggedIn")? (bool)Properties["IsLoggedIn"] : false;
    // The root page of your application
    if (isLoggedIn)
    {
        MainPage = new MasterPage();
    }
    else
    {
       MainPage = new NavigationPage(new carousel());
    }
}

carousel.cs carousel.cs

void funca(object sender, EventArgs e){
   MasterPage mp = new Menu();
   mp.Detail = new NavigationPage(new Detail());
   App.Current.MainPage = mp;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM