.xaml issue

Peter_1985 2,586 Reputation points

To .xaml component, how to show a prompt with "OK", "Cancel" buttons inside?

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
{count} votes

Accepted answer
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor


    If you want to pop up a prompt, there are several ways to achieve this.

    For example:

    1. Display Pop-ups Xamarin.Forms has three methods on the Page class for interacting with the user via a pop-up: DisplayAlert, DisplayActionSheet, and DisplayPromptAsync. They are rendered with appropriate native controls on each platform. For more , you can check document Display Pop-ups .
    2. use Rg.Plugins.Popup You can also use nuget Rg.Plugins.Popup . Rg.Plugins.Popup - is a cross platform plugin for Xamarin.Forms which allows you to open Xamarin.Forms pages as a popup that can be shared across iOS, Android, UWP, and macOS. Also the plugin allows you to use very simple and flexible animations for showing popup pages. For more information please check: https://github.com/rotorgames/Rg.Plugins.Popup .


    With DisplayActionSheet, can I have Yes, No buttons to it? Is there example lines to run it?

    For function DisplayActionSheet, you can just change the second and third parameters to yours.

    public Task<string> DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons)  
        return DisplayActionSheet(title, cancel, destruction, FlowDirection.MatchParent, buttons);  

    For example, we can change the cancel to No and change destruction to Yes, just as follows:

           private async void Button_Clicked(object sender, EventArgs e)  
            string action = await DisplayActionSheet("ActionSheet: SavePhoto?", "No", "Yes", "Photo Roll", "Email");  
            Debug.WriteLine("Action: " + action);  

    And when we click the No, the log is:

      Action: No  

    when we click the Yes, the log is:

     Action: Yes  

    Best Regards,
    Jessie Zhang

    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 additional answers

Sort by: Most helpful