Hi all -
This is my first post as a newbie Xamarin Forms programmer.
I am trying to do the following:
1. Load a page (FooStart.xaml)
2. When I tap a button on that page, a modal window (FooModal.xaml) should load. I want this modal page to act like a pop-up menu for FooStart.
3. When I tap one of the buttons/labels in the modal window that forwards to other pages, I want the modal window to disappear and I want to be forwarded to the new page (FooEnd.xaml, for example), such that the back button on FooEnd.xaml will take me back to FooStart.xaml.
I am trying the code below, as well as various configurations, but the code that runs when the button in the modal is tapped causes the application to crash. Can anyone tell me how to accomplish this using the navigation stack? (I know there are pop-up packages out there, but this is the preferred way at this time, if it can be made to work.)
FooStart.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="SMS.FooStart"
Title="FooStart">
<ContentPage.Content>
<StackLayout>
<Button Text="Open FooModal" Clicked="Button_Clicked" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
FooStart.xaml.cs
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace SMS
{
public partial class FooStart : ContentPage
{
public FooStart()
{
InitializeComponent();
}
async private void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new FooModal());
}
}
}
FooModal.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="SMS.FooModal">
<ContentPage.Content>
<StackLayout>
<Button Text="Go to FooEnd" Clicked="Button_Clicked" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
FooModal.xaml.cs
using System;
using Xamarin.Forms;
namespace SMS
{ public partial class FooModal : ContentPage
{
public FooModal()
{
InitializeComponent();
}
async private void Button_Clicked(object sender, EventArgs e)
{
Navigation.InsertPageBefore(new FooEnd(), this);
await Navigation.PopModalAsync();
}
}
}
FooEnd.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="SMS.FooEnd"
Title="FooEnd">
<ContentPage.Content>
<StackLayout>
<Label Text="This is FooEnd" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
FooEnd.xaml.cs
using Xamarin.Forms;
namespace SMS
{
public partial class FooEnd : ContentPage
{
public FooEnd()
{
InitializeComponent();
}
}
}