I have a app where in I would like to have a master page with 2 options and toolbarItems for each of the details page.
For example, here I have a settings page as my details page which has two tollbaritems save and cancel. It is form wherein user has to put in userdata which has to get saved. So on click of save toolbarItem I would like to save the data and redirect user to some other page (say 'PageA') which is not included in Masterpage list options(Settins, Login)
How can I go about it? If I do await Navigation.PushAsync(new PageA()); I do not get masterpage. I get back icon to go back to master details page. But I would like to redirect user to a page which should also have masterdetails option(settings and login).
I also tried this in save button click:
MasterDetailPage MDPage = new MasterDetailPage();
MDPage.Detail = new NavigationPage(new PageA());
MDPage.IsPresented = false;
Thanks in advance.
Edit Here is my code:
MasterPage.cs
public ListView ListView { get { return listView; } }
ListView listView;
public MasterPage()
{
var masterPageItems = new List<MasterPageItem>();
masterPageItems.Add(new MasterPageItem
{
Title = "Settings",
//IconSource = "Settings.png",
TargetType = typeof(TestPage)
});
listView = new ListView
{
ItemsSource = masterPageItems,
ItemTemplate = new DataTemplate(() =>
{
var imageCell = new ImageCell();
imageCell.SetBinding(TextCell.TextProperty, "Title");
imageCell.SetBinding(ImageCell.ImageSourceProperty, "IconSource");
return imageCell;
}),
VerticalOptions = LayoutOptions.FillAndExpand,
SeparatorVisibility = SeparatorVisibility.None
};
Padding = new Thickness(0, 40, 0, 0);
// Icon = "hamburger.png";
Title = "Menu";
BackgroundColor = Color.FromHex("#4F6276");
Content = new StackLayout
{
VerticalOptions = LayoutOptions.FillAndExpand,
Children = {
listView
}
};
}
MasterDetailsPage:
public class MainPage : MasterDetailPage
{
public MainPage()
{
MasterPage masterPage;
masterPage = new MasterPage();
Master = masterPage;
Detail = new NavigationPage(new TestPage())
{
//Tint = Color.Red // put your color here
BarBackgroundColor = Color.FromRgb(172, 183, 193),//Color.FromHex("#9E9E9E"),
BarTextColor = Color.Black,
BackgroundColor = Color.White
};
}
}
TestPage:
public class TestPage : ContentPage
{
public TestPage()
{
Button test = new Button();
test.Clicked += test_Clicked;
test.Text = "Save";
Button test1 = new Button();
test1.Clicked += test1_Clicked;
test1.Text = "cancel";
Content = new StackLayout
{
Children = {
test,
test1
}
};
}
void test_Clicked(object sender, EventArgs e)
{
//redirect to new page(Page1)
}
void test1_Clicked(object sender, EventArgs e)
{
//redirect to new page(Page2)
}
}
I want to redirect to a new page say page1 from onclick event. How do I achieve this?
