无法在ContentDialog中处理BackButton
当打开无法在ContentDialog中处理BackButton,button,win-universal-app,uwp,Button,Win Universal App,Uwp,当打开ContentDialog并按下设备的硬件/软件BackButton时,是否有方法引发任何事件?当ContentDialog打开时按下back按钮将不会引发Windows.UI.Core.SystemNavigationManager.BackRequested事件 但是,它将关闭ContentDialog,并按该顺序触发ContentDialog的关闭和关闭事件。此外,如果通过“上一步”按钮关闭,ContentDialog.ShowAsync()将返回“无”。下面的示例演示了这三种方法
ContentDialog
并按下设备的硬件/软件BackButton时,是否有方法引发任何事件?当ContentDialog打开时按下back按钮将不会引发Windows.UI.Core.SystemNavigationManager.BackRequested事件
但是,它将关闭ContentDialog,并按该顺序触发ContentDialog的关闭和关闭事件。此外,如果通过“上一步”按钮关闭,ContentDialog.ShowAsync()将返回“无”。下面的示例演示了这三种方法
var cd = new ContentDialog() {
Title = "Test Dialog",
Content = "This is a test content dialog. Hit the back button now.",
PrimaryButtonText = "OK",
};
cd.Closing += (ContentDialog s, ContentDialogClosingEventArgs ev) => { new MessageDialog("Event 1 fired.").ShowAsync(); };
cd.Closed += (ContentDialog s, ContentDialogClosedEventArgs ev) => { new MessageDialog("Event 2 fired.").ShowAsync(); };
var result = await cd.ShowAsync();
if (result == ContentDialogResult.None)
{
new MessageDialog("Back button was pressed.").ShowAsync();
}
希望有帮助!如果没有,请告诉我。:)
更新:
我想到的另一个解决方案是通过取消关闭事件并添加您想要的任何行为来处理关闭事件。这将阻止ContentDialog关闭
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
var cd = new ContentDialog()
{
Title = "Test Dialog",
Content = "This is a test content dialog. Hit the back button now.",
PrimaryButtonText = "OK",
};
cd.Closing += Cd_Closing;
await cd.ShowAsync();
}
private void Cd_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
{
if (args.Result == ContentDialogResult.None)
{
args.Cancel = true;
// Handle back press here instead of closing.
}
}
你到底想要这个干什么?想要这些功能的目的是什么?谢谢你的解决方案,贾里德。我已经做了这个测试,但是当对话框中有2到3个按钮(必须返回正确的结果)时,它就不起作用了+1用于解决问题,但不幸的是,这对我没有多大帮助。“后退”按钮只能在类似向导的对话框中起作用。