4

How to dismiss the popup in xamarin forms? I am displaying an alert popup by calling

var actionButton2 = new Button { Text = "ActionSheet" };
actionButton2.Clicked += async (sender, e) => {
    var action = await DisplayActionSheet ("ActionSheet: Save Photo?", "Cancel", "Delete", "Photo Roll", "Email");
    Debug.WriteLine("Action: " + action); // writes the selected button label to the console
};

Now how can i dismiss it programatically ?

Rajesh Batth
  • 1,672
  • 2
  • 19
  • 23
  • Just to clarify: In which case would you want to do this? IMHO you need the user to react if you show the ActionSheet. – angak Jan 16 '15 at 10:32
  • 1
    In my case, someone else closed the dialog. User A sends request. User B does nothing. User A ends request. I want to hide the request for User B. – nVentimiglia Sep 03 '15 at 23:12
  • The real answer is the interface was designed poorly. All other methods that act this way have an 'Async' suffix and all that I've used have an option for a cancellation token, which would have worked in any OS. – Quark Soup Nov 12 '20 at 01:47

2 Answers2

1

You can't.

An action sheet is designed for user interaction, not for programmatic interaction. The entire idea of an action sheet is that the program flow depends on user input at that point and cannot continue without this input.

So the user has to do something with the action sheet or dismiss it by pressing the hardware back button.

Thomas Weller
  • 11,631
  • 3
  • 26
  • 34
  • Sorry, but this is simply a very, very poorly designed interface and your logic is naive. I can easily see something like an error message that pops up when you have a communication error, gives the user the option to exit out of the application, or just hang around until the error clears up. If a communication error clears up all on it's own, you want to dismiss the pop-up alert programmatically. – Quark Soup Nov 12 '20 at 01:45
0

To give a more elaborate answer.

Xamarin.Forms method DisplayActionSheet doesn't support dismiss, so basically you can't. However native operating systems have their own methods to which DisplayActionSheet maps to. On iOS it is not possible to dismiss such an alert, but on Android it is: How to remove AlertDialog programmatically . So if you wish to dismiss the dialog on Android it is possible, but you would need to use the native method to invoke it.

Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57