Skip to content

Handle hardware buttons in Dialogs. #2380

Answered by Tum4ik
Tum4ik asked this question in Xamarin.Forms
Discussion options

You must be logged in to vote

Here is my workaround:

private readonly object _locker = new();
private readonly HashSet<string> _openDialogs = new();

public void OnNavigatedTo(INavigationParameters parameters)
{
  _openDialogs.Clear();
}

private ICommand? _shutdownButtonClickedCommand;
public ICommand ShutdownButtonClickedCommand =>
  _shutdownButtonClickedCommand ??= new DelegateCommand(ShutdownButtonClicked);

private void ShutdownButtonClicked()
{
  lock (_locker)
  {
    if (!_openDialogs.Contains(D.AppExitConfirmationDialog))
    {
      _openDialogs.Add(D.AppExitConfirmationDialog);
      _dialogService.ShowDialog(D.AppExitConfirmationDialog);
    }
  }
}

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Tum4ik
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Tum4ik
Comment options

You must be logged in to vote
1 reply
@Tum4ik
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants