How to change detail page to the other detail page?

I want to change detail page to the other detail page. The other words, when I click the masterpage's button, The detail page will be changed.

Here's my code:

void MyPageClicked(object sender, EventArgs e)
{
new MainPage().Detail = new MyPage();
((MasterDetailPage)Parent).IsPresented = false;
}

'((MasterDetailPage)Parent).IsPresented=false;' is worked, but 'new MainPage().Detail=new MyPage();' code isn;t worked. How do I change the code?

Answers

  • AlexanderDavikAlexanderDavik USMember ✭✭

    That is very simple, you need to take a serious look at the navigation, the navigation is from a page to jump to another page

  • SanGu.0696SanGu.0696 KRMember

    I don't want to use navigation page. I want to change other detail page in same master page.

  • MaxMengMaxMeng NZMember ✭✭✭

    Xamarin suggest use NavigationPage as your DetailPage, then push/pop

    Anyway, you can simply assign Master.Detail with your new page.

  • SanGu.0696SanGu.0696 KRMember

    Okay, but I'm using carousel page with detail page. Can I use carousel page in navigation page?

  • SanGu.0696SanGu.0696 KRMember
    edited June 2016

    I want to set several detail page in one master page. any idea?

  • SanGu.0696SanGu.0696 KRMember

    I fixed my code:

        public void MyPageClicked(object sender, EventArgs e)
        {
            new MainPage().Detail.Navigation.PushAsync(new MyPage());
            ((MasterDetailPage)Parent).IsPresented = false;
        }
    }
    

    but it doesn't work. Why?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    You can change your detail to whichever page you want. I don't understand very well your code. Why that "new " before setting the detail? Can to post the entire code?

  • SanGu.0696SanGu.0696 KRMember
    edited June 2016

    MainPage.xaml:
    <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:App25;assembly=App25" x:Class="App25.MainPage"> <MasterDetailPage.Master> <local:MasterPage /> </MasterDetailPage.Master> <MasterDetailPage.Detail> <local:HomePage /> </MasterDetailPage.Detail> </MasterDetailPage>

    MainPage.xaml.cs:
    public partial class MainPage : MasterDetailPage { public MainPage() { InitializeComponent(); } }
    MasterPage.xaml.cs:
    public void MyPageClicked(object sender, EventArgs e) { new MainPage().Detail.Navigation.PushAsync(new MyPage()); ((MasterDetailPage)Parent).IsPresented = false; }

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Sorry I don't know xaml very well, but where you call mypageclicked?

  • SanGu.0696SanGu.0696 KRMember

    On xaml code:
    <controls:ImageButton Grid.Column="0" Orientation="ImageOnBottom" ImageHeightRequest="40" ImageWidthRequest="40" Text="MyPage" Source="ic_face_white_48dp.png" BackgroundColor="#663300" TextColor="White" BorderRadius="0" HorizontalOptions="FillAndExpand" FontSize="8" FontAttributes="Bold" HeightRequest="70" Clicked="MyPageClicked"/>

  • SanGu.0696SanGu.0696 KRMember

    Ok, then Can I use button to open detail page, not listview?

  • Matt_PerleyMatt_Perley CAMember ✭✭

    this should be what you are looking for ,if i understand what you are after correctly. forgive me if i misread the need.

    var item = e.SelectedItem as MasterNavMenuItem;
    if (item == null)
    return;
    if (item.Title == "Home")
    {
    HomePage HP = new HomePage();
    HP.Title = item.Title;
    await Detail.Navigation.PushAsync(HP);
    }
    IsPresented = false;

            MasterPage.ListView.SelectedItem = null;
    

    just an example. everyone codes differently, i apologize if this does not suit your needs.

  • omrs24omrs24 Member

    Hello, just found this post and probably you've already solve it, but i want to share the way i fix this

            Navigation.PushModalAsync(new MainPage()
                    {
                        Detail = new NavigationPage(new MyPage())
                    }); 
    
  • aliZAKRIAaliZAKRIA USMember ✭✭

    @omrs24 said:
    Hello, just found this post and probably you've already solve it, but i want to share the way i fix this

          Navigation.PushModalAsync(new MainPage()
                    {
                        Detail = new NavigationPage(new MyPage())
                    }); 
    

    thaks that helped me :smiley:

Sign In or Register to comment.