Hey,
how can I change the Detail Element from MasterDetailPage in the codebehind of the actual DetailPage?
E.g. I want to set a new DetailPage when the user clicks on an Image in the DetailPage.
I do it here around line 140! https://github.com/jamesmontemagno/Hanselman.Forms/blob/master/Hanselman.Portable/Views/HomeView.cs
Answers
Up, I have exactly the same question, let suppose that I am using the same MVVM architecture as @JamesMontemagno in this project https://github.com/jamesmontemagno/Hanselman.Forms.
How to set new
Detail
page when I want to navigate to from anotherDetail
page?I do it here around line 140! https://github.com/jamesmontemagno/Hanselman.Forms/blob/master/Hanselman.Portable/Views/HomeView.cs
@JamesMontemagno thank you!
But lets suppose that we are in this line:
https://github.com/jamesmontemagno/Hanselman.Forms/blob/master/Hanselman.Portable/Views/BlogPage.xaml.cs#L29
and would like to open:
https://github.com/jamesmontemagno/Hanselman.Forms/blob/master/Hanselman.Portable/Views/BlogDetailsView.cs
and still be in the
MasterDetail
scenario, not usingthis.Navigation.PushAsync(new Page())
which will opennew Page()
in the new window, outside theMasterDetail
, you know that I mean?@tkowalczyk
It opens the new Page in the DetailElement if you create the NavigationPage on the DetailElement in the Master as in @JamesMontemagno 's example in the lines below.
in Master:
var homeNav = new NavigationPage(master.PageSelection) { BarBackgroundColor = Color.FromHex("#3498DB"), BarTextColor = Color.White }; Detail = homeNav;
In Detail:
then you call
this.Navigation.PushAsync(new Page())
in your Detail Page... so the new page comes on your Detail Container.It works for me now!
@mra thx, so maybe I am doing smth wrong, could you check at my sample repo here:
https://github.com/tkowalczyk/SimpleMasterDetailTabbed
in my master I have as follow:
https://github.com/tkowalczyk/SimpleMasterDetailTabbed/blob/master/SimpleMasterDetailTabbed/SimpleMasterDetailTabbed/Views/MainView.cs
and in my Detail I am openning new view like so:
https://github.com/tkowalczyk/SimpleMasterDetailTabbed/blob/master/SimpleMasterDetailTabbed/SimpleMasterDetailTabbed/Views/PageOneView.cs#L23
But it still opens my
FeedbackView
in the new Page, at the top and not in the Detail container.Can you explain me what did I missed?
@tkowalczyk i've tested your code on iPad and it opened the Page
in the Detail container as it should in horizontal mode.
In portrait the master flies out so it looks like it's opened
on the whole page because the Menu Button is replaced with a "Back" Button.
You can set
this.MasterBehavior = MasterBehavior.Split;
orIsPresented = true;
in your BaseView.@mra I am testing your solution on android device and emulator and it doesn't help me:
https://github.com/tkowalczyk/SimpleMasterDetailTabbed/blob/master/SimpleMasterDetailTabbed/SimpleMasterDetailTabbed/Views/MainView.cs#L31 causes that menu is opened from the beginning and this line:
https://github.com/tkowalczyk/SimpleMasterDetailTabbed/blob/master/SimpleMasterDetailTabbed/SimpleMasterDetailTabbed/Views/MainView.cs#L33 makes nothing. Maybe do have some other ideas? Could you run this repo on android ?
maybe it's because you still set
isPresented = false
when you open a new detail ?https://github.com/tkowalczyk/SimpleMasterDetailTabbed/blob/master/SimpleMasterDetailTabbed/SimpleMasterDetailTabbed/Views/MainView.cs#L62
Sorry I don't have a android licence I only can run this on iOS and there it is in the detail... i think its only a visual problem.
@mra your solution is working on iPads because the menu is always visible
IsPresented = true
but it is not working on iPhone or android device or emulator, I will have to find how to make it working, but big thanks for your help, if you will find something interesting in this topic, please let me knowHi All, finally I found out two solution which works for me, more info here:
https://github.com/tkowalczyk/SimpleMasterDetailTabbed/commit/3821a0b6445c98d82b800d1b93c43bf31aa909e8
Hi I found a method to replace the Detail Page of MasterDetailPage, I think it may better. I get the reference of the MainPage from the App class which is the global context.
Link is dead, @JamesMontemagno what was your solution?
@Jan-DavidStrk https://github.com/jamesmontemagno/Hanselman.Forms/blob/master/Hanselman.Portable/Views/RootPage.cs#L31
@JamesMontemagno Hi There, the link is dead again. Could anyone post the code for this? Thanks in advance.
Seen this by @xinmeng
mainPage.Detail = new NavigationPage(new Home());
Does anyone know how to pass Prism navigation parameters this way?