how to custom action sheet?

mc 4,716 Reputation points
2024-11-20T04:51:24.49+00:00

I can show action sheet using :

await Shell.Current.DisplayActionSheet("choose...","cancel",null,["OPT1"]);

but how to custom it ?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,650 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,786 Reputation points Microsoft Vendor
    2024-11-21T02:24:30.33+00:00

    Hello,

    custom action sheet?

    No, no handlers to custom this action shell, if you want to custom popup alert, you can use

    Communitytoolkit Popup to do it.

    For example, I install this CommunityToolkit.Maui, then Initializing the package in MauiProgram.cs

    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .UseMauiCommunityToolkit()
    

    Then create a ContentPage and change the type to toolkit:Popup, After that, you can add controls that you want. I add following controls for testing.

    <?xml version="1.0" encoding="utf-8" ?>
    <toolkit:Popup 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"
                 x:Class="MauiApp5.MyPopUp"
                >
        <VerticalStackLayout>
            <Label 
                Text="Welcome to .NET MAUI!"
                VerticalOptions="Start" 
                HorizontalOptions="Start"
                FontSize="Title"
                />
            <Entry
                 VerticalOptions="Center" 
                 HorizontalOptions="FillAndExpand"
                
                />
            <Entry
          VerticalOptions="Center" 
          HorizontalOptions="FillAndExpand"
         
         />
            <Button
                 VerticalOptions="End" 
                 HorizontalOptions="End"
                Text="login"
                ></Button>
        </VerticalStackLayout>
    </toolkit:Popup>
    

    Do not forget to change background code's contentpage to Popup

    using CommunityToolkit.Maui.Views;
    
    namespace MauiApp5;
    
    public partial class MyPopUp : Popup
    {
    	public MyPopUp()
    	{
    		InitializeComponent();
    	}
    }
    

    By the way, if your project's .NET version is 8.0, please install CommunityToolkit.Maui to 8.0.1

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.