【发布时间】:2014-05-11 16:15:10
【问题描述】:
我想在硬件上按下后退按钮时向用户显示一个 MessageBox,但它根本不起作用。我尝试了这些变体,但我从未看到 MessageBox:
// VARIATION 1
IAsyncResult mbResult = Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox("Warning", "Are you sure you want to leave this page?",
new string[] { "Yes", "No" }, 0, Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None, null, null);
mbResult.AsyncWaitHandle.WaitOne();
int? yesNo = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(mbResult);
if (yesNo.HasValue)
{
if (yesNo.Value == 0)
{
// Yes pressed
}
else
{
// No pressed
}
}
// VARIATION 2
MessageBoxResult mbr = MessageBox.Show("Are you sure you want to leave this page?", "Warning", MessageBoxButton.OKCancel);
if(mbr == MessageBoxResult.OK)
{
// OK pressed
}
else
{
// Cancel pressed
}
如果我将e.Cancel = true 写入OnBackKeyPress 事件,则我无法离开页面,因此代码正在执行,但我从未看到消息框:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
可能是什么问题,或者我做错了什么?
【问题讨论】:
标签: c# silverlight windows-phone-8 messagebox windows-phone-8.1