/
FormsApplicationPage.cs
86 lines (70 loc) · 2.21 KB
/
FormsApplicationPage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.ComponentModel;
using System.Windows;
using Xamarin.Forms.Platform.WPF.Controls;
namespace Xamarin.Forms.Platform.WPF
{
public class FormsApplicationPage : FormsWindow
{
protected Application Application { get; private set; }
protected Platform Platform { get; private set; }
public FormsApplicationPage()
{
System.Windows.Application.Current.Startup += OnLaunching;
System.Windows.Application.Current.Exit += OnClosing;
MessagingCenter.Send(this, WPFDeviceInfo.BWPorientationChangedName, this.ToDeviceOrientation());
SizeChanged += OnOrientationChanged;
this.ContentLoader = new FormsContentLoader();
}
public void LoadApplication(Application application)
{
Application.Current = application;
application.PropertyChanged += ApplicationOnPropertyChanged;
Application = application;
// Hack around the fact that OnLaunching will have already happened by this point, sad but needed.
application.SendStart();
}
void ApplicationOnPropertyChanged(object sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == "MainPage" && IsLoaded)
SetMainPage();
}
void OnActivated(object sender, System.EventArgs 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, ExitEventArgs e)
{
Application.SendSleep();
}
void OnDeactivated(object sender, System.EventArgs e)
{
Application.SendSleep();
}
void OnLaunching(object sender, StartupEventArgs e)
{
Application.SendStart();
}
void OnOrientationChanged(object sender, SizeChangedEventArgs e)
{
MessagingCenter.Send(this, WPFDeviceInfo.BWPorientationChangedName, this.ToDeviceOrientation());
}
void SetMainPage()
{
if (Platform == null)
Platform = new Platform(this);
Platform.SetPage(Application.MainPage);
}
protected override void Appearing()
{
base.Appearing();
SetMainPage();
}
public override void OnBackSystemButtonPressed()
{
Application.NavigationProxy.PopModalAsync();
}
}
}