0

I’m trying to create a pop up menu with buttons in the main page, to navigate to other pages using community toolkit but I’m having trouble with it. Is it possible to do a pop up control with navigation stack using Mopups library or any other?

This is an example of what I tried to do.

In the homepage.xaml.cs file, I created a handler

private async void OpenMenuPage(object sender, EventArgs e) { Navigation.PushAsync(new MenuPage()) }

The MenuPage is a contentPage. In the cs file I did something like this

private async void FirstPage_OnClicked(object sender, EventArgs e) { Navigation.PushAsync(new FirstPage(this)) }

private async void SecondPage_OnClicked(object sender, EventArgs e) { Navigation.PushAsync(new SecondPage(this)) }

I’m new with this..

Thanks!

2
  • "homepage.xaml.cs" - Is this a `NavigationPage"? That's what you need, if you want a navigation stack. Commented Jun 20, 2023 at 18:14
  • I want to see your application class. The place where you set MainPage = ... Commented Jun 22, 2023 at 10:38

1 Answer 1

0

I don't know if this still is wanted but I give a solution for using Popup's.

The Popup control xaml:

<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup
    x:Class="MauiTest.Controls.PopupControl"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    CanBeDismissedByTappingOutsideOfPopup="True"
    HorizontalOptions="Center"
    Color="White">

    <Grid
        Margin="10,10,10,10"
        HorizontalOptions="Center"
        RowDefinitions="*,*,2, *"
        VerticalOptions="Center">
        <Button
            x:Name="Button1"
            Grid.Row="0"
            BackgroundColor="Transparent"
            Clicked="Button1_Clicked"
            Text="Menu Item 1"
            TextColor="Black" />
        <Button
            x:Name="Button2"
            Grid.Row="1"
            BackgroundColor="Transparent"
            Clicked="Button2_Clicked"
            Text="Menu Item 2"
            TextColor="Black" />
        <BoxView Grid.Row="2" Color="LightGray" />
        <Button
            x:Name="Button4"
            Grid.Row="3"
            BackgroundColor="Transparent"
            Clicked="Button3_Clicked"
            Text="Menu Item 3"
            TextColor="Black" />
    </Grid>
</toolkit:Popup>

The Popup code behind:

using CommunityToolkit.Maui.Views;
using MauiTest.Views;

namespace MauiTest.Controls;

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PopupControl : Popup
{
    public PopupControl()
    {
        InitializeComponent();
    }

    private void Button1_Clicked(object sender, EventArgs e)
    {
        Close(new TestPage());
    }

    private void Button2_Clicked(object sender, EventArgs e)
    {
        Close(new TestPage());
    }

    private void Button3_Clicked(object sender, EventArgs e)
    {
        Close(new TestPage());
    }
}

And the implementation:

private async void MenuButtonClicked(object sender, EventArgs e)
{
    var popup = new PopupControl();
    var result = await Application.Current.MainPage.ShowPopupAsync(popup);

    if (result is ContentPage contentPageResult)
    {
        await Navigation.PushAsync(contentPageResult);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.