在UWP应用程序中,可以通过以下方式实现按下Escape键时ContentDialog消失:
private void ContentDialog_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Escape)
{
// 关闭ContentDialog
this.Hide();
}
}
这样,当用户按下Escape键时,ContentDialog将调用Hide()
方法关闭自身。