Closing MessageDialog programatically in WP 8.1 RT

試著忘記壹切 提交于 2019-12-12 02:27:35

问题


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?


回答1:


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();
}


来源:https://stackoverflow.com/questions/32820514/closing-messagedialog-programatically-in-wp-8-1-rt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!