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
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
I don't want to use navigation page. I want to change other detail page in same master page.
Xamarin suggest use NavigationPage as your DetailPage, then push/pop
Anyway, you can simply assign Master.Detail with your new page.
Okay, but I'm using carousel page with detail page. Can I use carousel page in navigation page?
I want to set several detail page in one master page. any idea?
I fixed my code:
but it doesn't work. Why?
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?
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; }
Sorry I don't know xaml very well, but where you call mypageclicked?
https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/
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"/>
Ok, then Can I use button to open detail page, not listview?
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;
just an example. everyone codes differently, i apologize if this does not suit your needs.
Hello, just found this post and probably you've already solve it, but i want to share the way i fix this
thaks that helped me