WinPhone: How to add custom confirmation dialog in OnBackKeyPress
I am going to implement custom confirmation dialog in OnBackKeyPress
method. It is easy to do with native message box:
protected override void OnBackKeyPress(CancelEventArgs e)
{
base.OnBackKeyPress(e);
MessageBoxResult result = MessageBox.Show("Text");
if(result==MessageBoxResult.OK)
{
e.Cancel = true;
}
}
It works, but I dislike limitation with two buttons so I am looking for
something else.
I have checked 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();
}
}
And 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();
}
Both looks good, but don't work in OnBackKeyPress method (show and
immediately disappear without any my action).
Moreover, I've tried 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);
}
}
It works as I expected (has customs in OnBackKeyPress method), but I don't
sure that using XNA inside Silverlight app is good practice.
So, I am looking a way to use WPtoolkit or Coding4Fun windows inside
OnBackKeyPress method or any explanation about using XNA inside
Silverlight app (any recomendation or info about approval such kind app by
store).
No comments:
Post a Comment