如何防止 ContentDialog 在 WP8 中按下按钮时关闭

who*_*ows 2 windows-phone-8

在 Windows Phone 8(或 8.1)中,有没有办法防止在某些条件下按下主按钮时 ContentDialog 关闭?例如,假设您完成了一个布尔运算。当他们单击主按钮时,我只希望 ContentDialog 在 (done == true) 时关闭。这可能吗?

Alm*_*mis 5

XAML:

<ContentDialog
    ...
    Closing="ContentDialog_Closing">
Run Code Online (Sandbox Code Playgroud)

C#:

private async void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
    if (!CanClose)
        args.Cancel = true;
}
Run Code Online (Sandbox Code Playgroud)