在 WP 8.1 RT 中以编程方式关闭 MessageDialog [英] Closing MessageDialog programatically in WP 8.1 RT
问题描述
我想关闭并隐藏 Windows Phone 8.1 RT 中的 MessageDialog
.我已经通过调用 .Cancel()
和 .Close()
看到了多种解决方案,但没有一个适用于 Windows Phone 8.1 RT;它们仅对 Windows 8 RT 有效.
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.
如何在不与其交互的情况下从代码中关闭 MessageDialog
?
How can I close the MessageDialog
from code without interacting with it?
推荐答案
使用 ContentDialog
代替 MessageDialog
.ContentDialog 有更多的自定义选项.您可以毫无问题地创建看起来像 MessageDialog 的 ContentDialog,并将其隐藏在代码中.
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.
示例:
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();
}
这篇关于在 WP 8.1 RT 中以编程方式关闭 MessageDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!