LayoutAwarePage.h 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //*********************************************************
  2. //
  3. // Copyright (c) Microsoft. All rights reserved.
  4. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  5. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  6. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  7. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  8. //
  9. //*********************************************************
  10. #pragma once
  11. #include <collection.h>
  12. namespace SDKSample
  13. {
  14. namespace Common
  15. {
  16. /// <summary>
  17. /// Typical implementation of Page that provides several important conveniences:
  18. /// <list type="bullet">
  19. /// <item>
  20. /// <description>Application view state to visual state mapping</description>
  21. /// </item>
  22. /// <item>
  23. /// <description>GoBack, GoForward, and GoHome event handlers</description>
  24. /// </item>
  25. /// <item>
  26. /// <description>Mouse and keyboard shortcuts for navigation</description>
  27. /// </item>
  28. /// <item>
  29. /// <description>State management for navigation and process lifetime management</description>
  30. /// </item>
  31. /// <item>
  32. /// <description>A default view model</description>
  33. /// </item>
  34. /// </list>
  35. /// </summary>
  36. [Windows::Foundation::Metadata::WebHostHidden]
  37. public ref class LayoutAwarePage : Windows::UI::Xaml::Controls::Page
  38. {
  39. internal:
  40. LayoutAwarePage();
  41. public:
  42. void StartLayoutUpdates(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
  43. void StopLayoutUpdates(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
  44. void InvalidateVisualState();
  45. static property Windows::UI::Xaml::DependencyProperty^ DefaultViewModelProperty
  46. {
  47. Windows::UI::Xaml::DependencyProperty^ get();
  48. };
  49. property Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::Object^>^ DefaultViewModel
  50. {
  51. Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::Object^>^ get();
  52. void set(Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::Object^>^ value);
  53. }
  54. protected:
  55. virtual void GoHome(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
  56. virtual void GoBack(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
  57. virtual void GoForward(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
  58. virtual Platform::String^ DetermineVisualState(Windows::UI::ViewManagement::ApplicationViewState viewState);
  59. virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
  60. virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
  61. virtual void LoadState(Platform::Object^ navigationParameter,
  62. Windows::Foundation::Collections::IMap<Platform::String^, Platform::Object^>^ pageState);
  63. virtual void SaveState(Windows::Foundation::Collections::IMap<Platform::String^, Platform::Object^>^ pageState);
  64. private:
  65. Platform::String^ _pageKey;
  66. bool _navigationShortcutsRegistered;
  67. Platform::Collections::Map<Platform::String^, Platform::Object^>^ _defaultViewModel;
  68. Windows::Foundation::EventRegistrationToken _windowSizeEventToken,
  69. _acceleratorKeyEventToken, _pointerPressedEventToken;
  70. Platform::Collections::Vector<Windows::UI::Xaml::Controls::Control^>^ _layoutAwareControls;
  71. void WindowSizeChanged(Platform::Object^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ e);
  72. void OnLoaded(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
  73. void OnUnloaded(Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
  74. void CoreDispatcher_AcceleratorKeyActivated(Windows::UI::Core::CoreDispatcher^ sender,
  75. Windows::UI::Core::AcceleratorKeyEventArgs^ args);
  76. void CoreWindow_PointerPressed(Windows::UI::Core::CoreWindow^ sender,
  77. Windows::UI::Core::PointerEventArgs^ args);
  78. LayoutAwarePage^ _this; // Strong reference to self, cleaned up in OnUnload
  79. };
  80. }
  81. }