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