Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent the ContentDialog from closing when home key is pressed in Windows phone 8.1..?

private IAsyncOperation<ContentDialogResult> _Task = null;
private ContentDialog _message = null;            


        _message = new ContentDialog()
        {
            Content = "Hello",
            PrimaryButtonText = "EXIT",
            IsPrimaryButtonEnabled = true,
        };

        _message.PrimaryButtonClick += message_PrimaryButtonClick;
        _Task = _message.ShowAsync();

Here I have created a Task for content Dialog, so that I can close the ContenDialog explicitly from code.

 How can I prevent dialog from closing when Home key is pressed and relaunched 
like image 717
Jose John Thottungal Avatar asked Mar 02 '15 10:03

Jose John Thottungal


1 Answers

To prevent the dialog from closing handle its Closing event and set Cancel to true in its ContentDialogClosingEventArgs argument.

When initializing the dialog:

myContentDialog.Closing += ContentDialog_Closing; 

Event handler:

void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
    if (doNotClose)
    {
        args.Cancel = true;
    }
}
like image 146
Rob Caplan - MSFT Avatar answered Oct 12 '22 01:10

Rob Caplan - MSFT