-->

如何拒绝来自代码的Windows Phone 8.1 MessageDialog(How to di

2019-10-22 03:12发布

我怎样才能解雇消息中的Windows Phone 8.1编程对话框。 我创建使用showAsync对话框()。 如果这是不可能的这是创建一个自定义消息具有以下属性对话框中的最好方法:

1. It can show test and hold buttons for user interaction.
2. It can be dismissed programmatically
3. Should block the view as a Normal MessageDialog do

Answer 1:

使用ContentDialog而非MessageDialog。 这也将让自定义对话框,以便你,除非你想要做的事真的疯了无需编写自定义控制。

在Windows上,MessageDialog是取消的,但不是在Windows Phone:

// Cancel the MessageDialog after 3 seconds on Windows
private async void Button_Click(object sender, RoutedEventArgs e)
{
    MessageDialog md = new MessageDialog("Lorem ipsum dolor sit amet","Message Dialog Title");
    var t = md.ShowAsync();

    await Task.Delay(TimeSpan.FromSeconds(3));

    // Ignored by the Windows Phone MessageDialog
    t.Cancel();
}

您可以在Windows Phone类似的代码取消ContentDialog。 您可以使用Visual Studio的ContentDialog模板,如果需要创建一个自定义ContentDialog。

private async void Button_Click(object sender, RoutedEventArgs e)
{
    ContentDialog cd = new ContentDialog();
    cd.Title = "Content Dialog";
    cd.PrimaryButtonText = "Close";
    cd.Content = "Lorem ipsum dolor sit amet";
    var t = cd.ShowAsync();

    await Task.Delay(TimeSpan.FromSeconds(3));

    t.Cancel();
}


文章来源: How to dismiss a MessageDialog from code in Windows Phone 8.1