locked
How to change detail page to the other detail page? RRS feed

  • Question

  • User204436 posted

    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?

    Friday, June 10, 2016 2:50 AM

All replies

  • User226803 posted

    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

    Friday, June 10, 2016 2:55 AM
  • User204436 posted

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

    Friday, June 10, 2016 3:22 AM
  • User92384 posted

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

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

    Friday, June 10, 2016 4:13 AM
  • User204436 posted

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

    Friday, June 10, 2016 4:28 AM
  • User204436 posted

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

    Friday, June 10, 2016 5:14 AM
  • User204436 posted

    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?

    Friday, June 10, 2016 5:51 AM
  • User2148 posted

    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?

    Friday, June 10, 2016 6:05 AM
  • User204436 posted

    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; }

    Friday, June 10, 2016 7:24 AM
  • User2148 posted

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

    Friday, June 10, 2016 7:43 AM
  • User2148 posted

    https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/

    Friday, June 10, 2016 7:45 AM
  • User204436 posted

    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"/>

    Friday, June 10, 2016 7:46 AM
  • User204436 posted

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

    Friday, June 10, 2016 7:53 AM
  • User357575 posted

    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.

    Thursday, November 23, 2017 7:35 PM
  • User387628 posted

    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())
                    }); 
    
    Monday, July 22, 2019 3:54 PM
  • User261196 posted

    @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:

    Thursday, September 19, 2019 4:08 PM
  • User396038 posted

    Hello how are you? Try doing it this way. Create 2 MasterDetailPage. Ex: ( mainPageLogin and mainPageLogon). After creating the pages, in the App class, the login page starts. After you log in at the end of the login confirmation method place the call from the other MasterDetailPage.

    Application.Current.MainPage = new NavigationPage(new mainPageLogon());
    This will load the MasterDetailPage page, which the person logged in to. And to make Logoff do the same process, but point to the login page.

    Application.Current.MainPage = new NavigationPage(new mainPageLogin());

    So the code that should be used is ( "Application.Current.MainPage = new NavigationPage(new PAGE());" )

    I hope I helped!

    Saturday, August 1, 2020 3:43 PM