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?
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.