summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/FormsApplicationPage.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 20:02:25 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-03-22 23:13:41 (GMT)
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.WP8/FormsApplicationPage.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
Initial import
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 0000000..ac6decb
--- /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