1

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
4

1 に答える 1

7

MessageDialog ではなく ContentDialog を使用します。これにより、ダイアログのカスタマイズも可能になるため、非常にクレイジーなことをしたい場合を除き、カスタム コントロールを記述する必要はありません。

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();
}
于 2015-03-02T02:00:30.770 に答える