Merge branch 'master' of github.com:purplecabbage/cordova-wp7
diff --git a/templates/standalone/cordovalib/Commands/Notification.cs b/templates/standalone/cordovalib/Commands/Notification.cs
index 9cfd528..4089e3e 100644
--- a/templates/standalone/cordovalib/Commands/Notification.cs
+++ b/templates/standalone/cordovalib/Commands/Notification.cs
@@ -23,6 +23,7 @@
using Microsoft.Xna.Framework.Audio;
using WPCordovaClassLib.Cordova.UI;
+
namespace WPCordovaClassLib.Cordova.Commands
{
public class Notification : BaseCommand
@@ -83,7 +84,6 @@
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
-
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
AlertOptions alertOpts = new AlertOptions();
alertOpts.message = args[0];
@@ -96,7 +96,9 @@
Grid grid = page.FindName("LayoutRoot") as Grid;
if (grid != null)
{
+ var previous = notifyBox;
notifyBox = new NotificationBox();
+ notifyBox.Tag = previous;
notifyBox.PageTitle.Text = alertOpts.title;
notifyBox.SubTitle.Text = alertOpts.message;
Button btnOK = new Button();
@@ -105,7 +107,11 @@
btnOK.Tag = 1;
notifyBox.ButtonPanel.Children.Add(btnOK);
grid.Children.Add(notifyBox);
- page.BackKeyPress += page_BackKeyPress;
+
+ if (previous == null)
+ {
+ page.BackKeyPress += page_BackKeyPress;
+ }
}
}
else
@@ -131,7 +137,9 @@
Grid grid = page.FindName("LayoutRoot") as Grid;
if (grid != null)
{
+ var previous = notifyBox;
notifyBox = new NotificationBox();
+ notifyBox.Tag = previous;
notifyBox.PageTitle.Text = alertOpts.title;
notifyBox.SubTitle.Text = alertOpts.message;
@@ -146,7 +154,10 @@
}
grid.Children.Add(notifyBox);
- page.BackKeyPress += page_BackKeyPress;
+ if (previous == null)
+ {
+ page.BackKeyPress += page_BackKeyPress;
+ }
}
}
else
@@ -159,15 +170,19 @@
void page_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
{
PhoneApplicationPage page = sender as PhoneApplicationPage;
+
if (page != null && notifyBox != null)
{
Grid grid = page.FindName("LayoutRoot") as Grid;
if (grid != null)
{
grid.Children.Remove(notifyBox);
+ notifyBox = notifyBox.Tag as NotificationBox;
}
- notifyBox = null;
- page.BackKeyPress -= page_BackKeyPress;
+ if (notifyBox == null)
+ {
+ page.BackKeyPress -= page_BackKeyPress;
+ }
e.Cancel = true;
}
@@ -177,12 +192,17 @@
void btnOK_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
+ FrameworkElement notifBoxParent = null;
int retVal = 0;
if (btn != null)
{
retVal = (int)btn.Tag + 1;
+
+ notifBoxParent = btn.Parent as FrameworkElement;
+ while ((notifBoxParent = notifBoxParent.Parent as FrameworkElement) != null &&
+ !(notifBoxParent is NotificationBox));
}
- if (notifyBox != null)
+ if (notifBoxParent != null)
{
PhoneApplicationPage page = Page;
if (page != null)
@@ -190,10 +210,15 @@
Grid grid = page.FindName("LayoutRoot") as Grid;
if (grid != null)
{
- grid.Children.Remove(notifyBox);
+ grid.Children.Remove(notifBoxParent);
+ }
+ notifyBox = notifBoxParent.Tag as NotificationBox;
+ if (notifyBox == null)
+ {
+ page.BackKeyPress -= page_BackKeyPress;
}
}
- notifyBox = null;
+
}
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, retVal));
}