HostLifecycleNotifications.WindowsPhone.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. #if WINDOWSPHONE7
  5. #if DEBUG_NO_AGENT_SUPPORT
  6. using Microsoft.Phone.Shell;
  7. #else
  8. using System.Reactive.PlatformServices.Phone.Shell;
  9. #endif
  10. namespace System.Reactive.PlatformServices
  11. {
  12. internal class HostLifecycleNotifications : IHostLifecycleNotifications
  13. {
  14. private EventHandler<ActivatedEventArgs> _activated;
  15. private EventHandler<DeactivatedEventArgs> _deactivated;
  16. public event EventHandler<HostSuspendingEventArgs> Suspending
  17. {
  18. add
  19. {
  20. _deactivated = (o, e) => value(o, new HostSuspendingEventArgs());
  21. var current = PhoneApplicationService.Current;
  22. if (current != null)
  23. current.Deactivated += _deactivated;
  24. }
  25. remove
  26. {
  27. var current = PhoneApplicationService.Current;
  28. if (current != null)
  29. current.Deactivated -= _deactivated;
  30. }
  31. }
  32. public event EventHandler<HostResumingEventArgs> Resuming
  33. {
  34. add
  35. {
  36. _activated = (o, e) =>
  37. {
  38. if (e.IsApplicationInstancePreserved)
  39. {
  40. value(o, new HostResumingEventArgs());
  41. }
  42. };
  43. var current = PhoneApplicationService.Current;
  44. if (current != null)
  45. current.Activated += _activated;
  46. }
  47. remove
  48. {
  49. var current = PhoneApplicationService.Current;
  50. if (current != null)
  51. current.Activated -= _activated;
  52. }
  53. }
  54. }
  55. }
  56. #endif