我将在OnBackKeyPress
方法中实现自定义确认对话框。使用本机消息框很容易做到:
protected override void OnBackKeyPress(CancelEventArgs e)
{
base.OnBackKeyPress(e);
MessageBoxResult result = MessageBox.Show("Text");
if(result==MessageBoxResult.OK)
{
e.Cancel = true;
}
}
它有效,但我不喜欢两个按钮的限制,所以我正在寻找其他东西。
我检查了 WPtoolkit:
private bool m_cansel = false;
protected override void OnBackKeyPress(CancelEventArgs e)
{
base.OnBackKeyPress(e);
if (!m_cansel)
{
e.Cancel = true;
m_cansel = true;
var messageBox = new CustomMessageBox
{
Title = "Title",
Message = "Message",
RightButtonContent = "aas",
IsLeftButtonEnabled = false,
};
messageBox.Dismissed += (sender, args) =>
{
};
messageBox.Show();
}
}
和 Coding4Fun:
private bool m_cansel = false;
protected override void OnBackKeyPress(CancelEventArgs e)
{
base.OnBackKeyPress(e);
if (!m_cansel)
{
e.Cancel = true;
m_cansel = true;
var messageBox = new MessagePrompt
{
Title = "Title",
Message = "Message",
};
messageBox.Completed += (sender, args) =>
{
//throw new NotImplementedException();
};
messageBox.Show();
}
两者看起来都不错,但不能按OnBackKeyPress
方法工作(显示并立即消失,无需我采取任何行动)。
此外,我尝试过 XNA:
private bool m_cansel = false;
protected override void OnBackKeyPress(CancelEventArgs e)
{
base.OnBackKeyPress(e);
if (!m_cansel)
{
e.Cancel = true;
m_cansel = true;
Guide.BeginShowMessageBox("Version of Windows", "Pick a version of Windows.",
new List<string> {"Vista", "Seven"}, 0, MessageBoxIcon.Error,
asyncResult =>
{
int? returned = Guide.EndShowMessageBox(asyncResult);
}, null);
}
}
它按我的预期工作(在OnBackKeyPress
方法上有习惯),但我不确定在 Silverlight 应用程序中使用 XNA 是一种好习惯。
因此,我正在寻找一种在方法内使用 WPtoolkit 或 Coding4Fun 窗口的OnBackKeyPress
方法,或任何关于在 Silverlight 应用程序中使用 XNA 的解释(任何关于通过商店批准此类应用程序的建议或信息)。