summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/FormsApplicationPage.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WP8/FormsApplicationPage.cs')
-rw-r--r--Xamarin.Forms.Platform.WP8/FormsApplicationPage.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WP8/FormsApplicationPage.cs b/Xamarin.Forms.Platform.WP8/FormsApplicationPage.cs
new file mode 100644
index 00000000..ac6decb6
--- /dev/null
+++ b/Xamarin.Forms.Platform.WP8/FormsApplicationPage.cs
@@ -0,0 +1,86 @@
+using System.ComponentModel;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
+
+namespace Xamarin.Forms.Platform.WinPhone
+{
+ public class FormsApplicationPage : PhoneApplicationPage
+ {
+ Application _application;
+ Platform _platform;
+
+ protected FormsApplicationPage()
+ {
+ PhoneApplicationService.Current.Launching += OnLaunching;
+ PhoneApplicationService.Current.Activated += OnActivated;
+ PhoneApplicationService.Current.Deactivated += OnDeactivated;
+ PhoneApplicationService.Current.Closing += OnClosing;
+
+ MessagingCenter.Send(this, Forms.WP8DeviceInfo.BWPorientationChangedName, Orientation.ToDeviceOrientation());
+ OrientationChanged += OnOrientationChanged;
+ //DeserializePropertyStore ();
+ }
+
+ protected void LoadApplication(Application application)
+ {
+ Application.Current = application;
+ application.PropertyChanged += ApplicationOnPropertyChanged;
+ _application = application;
+
+ // Hack around the fact that OnLaunching will haev already happened by this point, sad but needed.
+ application.SendStart();
+
+ SetMainPage();
+ }
+
+ void ApplicationOnPropertyChanged(object sender, PropertyChangedEventArgs args)
+ {
+ if (args.PropertyName == "MainPage")
+ SetMainPage();
+ }
+
+ void OnActivated(object sender, ActivatedEventArgs e)
+ {
+ // TODO : figure out consistency of get this to fire
+ // Check whether tombstoned (terminated, but OS retains information about navigation state and state dictionarys) or dormant
+ _application.SendResume();
+ }
+
+ // when app gets tombstoned, user press back past first page
+ void OnClosing(object sender, ClosingEventArgs e)
+ {
+ // populate isolated storage.
+ //SerializePropertyStore ();
+ _application.SendSleepAsync().Wait();
+ }
+
+ void OnDeactivated(object sender, DeactivatedEventArgs e)
+ {
+ // populate state dictionaries, properties
+ //SerializePropertyStore ();
+ _application.SendSleepAsync().Wait();
+ }
+
+ void OnLaunching(object sender, LaunchingEventArgs e)
+ {
+ // TODO : not currently firing, is fired before MainPage ctor is called
+ _application.SendStart();
+ }
+
+ void OnOrientationChanged(object sender, OrientationChangedEventArgs e)
+ {
+ MessagingCenter.Send(this, Forms.WP8DeviceInfo.BWPorientationChangedName, e.Orientation.ToDeviceOrientation());
+ }
+
+ void SetMainPage()
+ {
+ if (_platform == null)
+ _platform = new Platform(this);
+
+ _platform.SetPage(_application.MainPage);
+
+ if (!ReferenceEquals(Content, _platform))
+ Content = _platform.GetCanvas();
+ }
+ }
+} \ No newline at end of file