Reputation: 978
I want to close and hide the MessageDialog
in Windows Phone 8.1 RT. I've seen multiple solutions from calling .Cancel()
and .Close()
, but none work on Windows Phone 8.1 RT; they're valid only for Windows 8 RT.
How can I close the MessageDialog
from code without interacting with it?
Upvotes: 0
Views: 377
Reputation: 781
Use ContentDialog
instead MessageDialog
. ContentDialog has more customization options. You can create ContentDialog which looks like MessageDialog without any problems, and hide it from code.
Sample:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
ShowContentDialog("cos");
await HideContentDialog();
}
ContentDialog _contentDialog;
private void ShowContentDialog(string s)
{
_contentDialog = new ContentDialog();
_contentDialog.Content = s;
_contentDialog.IsPrimaryButtonEnabled = true;
_contentDialog.PrimaryButtonText = "OK";
_contentDialog.Title = "title";
_contentDialog.ShowAsync();
}
private async Task HideContentDialog()
{
await Task.Delay(5000);
_contentDialog.Hide();
}
Upvotes: 3