2222using Microsoft . UI . Xaml . Controls ;
2323using Microsoft . UI . Xaml . Input ;
2424using Microsoft . UI . Xaml . Navigation ;
25- using Windows . Devices . Input ;
2625using Windows . Foundation ;
2726using Windows . System . Profile ;
2827using Windows . UI . ViewManagement ;
@@ -34,9 +33,6 @@ public sealed partial class NavigationRootPage : Page
3433 {
3534 public Windows . System . VirtualKey ArrowKey ;
3635 public Microsoft . UI . Dispatching . DispatcherQueue dispatcherQueue ;
37-
38- private RootFrameNavigationHelper _navHelper ;
39- private bool _isKeyboardConnected ;
4036 private UISettings _settings ;
4137
4238
@@ -77,8 +73,6 @@ public NavigationRootPage()
7773 this . InitializeComponent ( ) ;
7874 dispatcherQueue = Microsoft . UI . Dispatching . DispatcherQueue . GetForCurrentThread ( ) ;
7975
80- _navHelper = new RootFrameNavigationHelper ( rootFrame , NavigationViewControl ) ;
81-
8276 SetDeviceFamily ( ) ;
8377 AddNavigationMenuItems ( ) ;
8478
@@ -91,27 +85,56 @@ public NavigationRootPage()
9185 }
9286 } ;
9387
94- _isKeyboardConnected = Convert . ToBoolean ( new KeyboardCapabilities ( ) . KeyboardPresent ) ;
95-
9688 // remove the solid-colored backgrounds behind the caption controls and system back button if we are in left mode
9789 // This is done when the app is loaded since before that the actual theme that is used is not "determined" yet
9890 Loaded += delegate ( object sender , RoutedEventArgs e )
9991 {
100- NavigationOrientationHelper . UpdateTitleBarForElement ( NavigationOrientationHelper . IsLeftMode ( ) , this ) ;
92+ NavigationOrientationHelper . UpdateNavigationViewForElement ( NavigationOrientationHelper . IsLeftMode ( ) , this ) ;
10193
10294 Window window = WindowHelper . GetWindowForElement ( sender as UIElement ) ;
10395 window . Title = AppTitleText ;
10496 window . ExtendsContentIntoTitleBar = true ;
97+ window . Activated += Window_Activated ;
10598 window . SetTitleBar ( this . AppTitleBar ) ;
10699
107100 AppWindow appWindow = WindowHelper . GetAppWindow ( window ) ;
108101 appWindow . SetIcon ( "Assets/Tiles/GalleryIcon.ico" ) ;
109102 _settings = new UISettings ( ) ;
110103 _settings . ColorValuesChanged += _settings_ColorValuesChanged ; // cannot use FrameworkElement.ActualThemeChanged event because the triggerTitleBarRepaint workaround no longer works
111104 } ;
105+ }
106+
107+ private void Window_Activated ( object sender , WindowActivatedEventArgs args )
108+ {
109+ if ( args . WindowActivationState == WindowActivationState . Deactivated )
110+ {
111+ VisualStateManager . GoToState ( this , "Deactivated" , true ) ;
112+ }
113+ else
114+ {
115+ VisualStateManager . GoToState ( this , "Activated" , true ) ;
116+ }
117+ }
112118
113- NavigationViewControl . RegisterPropertyChangedCallback ( NavigationView . PaneDisplayModeProperty , new DependencyPropertyChangedCallback ( OnPaneDisplayModeChanged ) ) ;
119+ private void OnPaneDisplayModeChanged ( NavigationView sender , NavigationViewDisplayModeChangedEventArgs args )
120+ {
121+ if ( sender . PaneDisplayMode == NavigationViewPaneDisplayMode . Top )
122+ {
123+ VisualStateManager . GoToState ( this , "Top" , true ) ;
124+ }
125+ else
126+ {
127+ if ( args . DisplayMode == NavigationViewDisplayMode . Minimal )
128+ {
129+ VisualStateManager . GoToState ( this , "Compact" , true ) ;
130+ }
131+ else
132+ {
133+ VisualStateManager . GoToState ( this , "Default" , true ) ;
134+ }
135+ }
114136 }
137+
115138 // this handles updating the caption button colors correctly when indows system theme is changed
116139 // while the app is open
117140 private void _settings_ColorValuesChanged ( UISettings sender , object args )
@@ -123,12 +146,6 @@ private void _settings_ColorValuesChanged(UISettings sender, object args)
123146 } ) ;
124147 }
125148
126- private void OnPaneDisplayModeChanged ( DependencyObject sender , DependencyProperty dp )
127- {
128- var navigationView = sender as NavigationView ;
129- NavigationRootPage . GetForElement ( this ) . AppTitleBar . Visibility = navigationView . PaneDisplayMode == NavigationViewPaneDisplayMode . Top ? Visibility . Collapsed : Visibility . Visible ;
130- }
131-
132149 // Wraps a call to rootFrame.Navigate to give the Page a way to know which NavigationRootPage is navigating.
133150 // Please call this function rather than rootFrame.Navigate to navigate the rootFrame.
134151 public void Navigate (
@@ -186,7 +203,7 @@ private void AddNavigationMenuItems()
186203 {
187204 foreach ( var group in ControlInfoDataSource . Instance . Groups . OrderBy ( i => i . Title ) . Where ( i => ! i . IsSpecialSection ) )
188205 {
189- var itemGroup = new Microsoft . UI . Xaml . Controls . NavigationViewItem ( ) { Content = group . Title , Tag = group . UniqueId , DataContext = group , Icon = GetIcon ( group . ImageIconPath ) } ;
206+ var itemGroup = new NavigationViewItem ( ) { Content = group . Title , Tag = group . UniqueId , DataContext = group , Icon = GetIcon ( group . ImageIconPath ) } ;
190207
191208 var groupMenuFlyoutItem = new MenuFlyoutItem ( ) { Text = $ "Copy Link to { group . Title } samples", Icon = new FontIcon ( ) { Glyph = "\uE8C8 " } , Tag = group } ;
192209 groupMenuFlyoutItem . Click += this . OnMenuFlyoutItemClick ;
@@ -196,7 +213,7 @@ private void AddNavigationMenuItems()
196213
197214 foreach ( var item in group . Items )
198215 {
199- var itemInGroup = new Microsoft . UI . Xaml . Controls . NavigationViewItem ( ) { IsEnabled = item . IncludedInBuild , Content = item . Title , Tag = item . UniqueId , DataContext = item } ;
216+ var itemInGroup = new NavigationViewItem ( ) { IsEnabled = item . IncludedInBuild , Content = item . Title , Tag = item . UniqueId , DataContext = item } ;
200217
201218 var itemInGroupMenuFlyoutItem = new MenuFlyoutItem ( ) { Text = $ "Copy Link to { item . Title } sample", Icon = new FontIcon ( ) { Glyph = "\uE8C8 " } , Tag = item } ;
202219 itemInGroupMenuFlyoutItem . Click += this . OnMenuFlyoutItemClick ;
@@ -249,7 +266,7 @@ private void SetDeviceFamily()
249266
250267 private void OnNewControlsMenuItemLoaded ( object sender , RoutedEventArgs e )
251268 {
252- if ( NavigationViewControl . DisplayMode == Microsoft . UI . Xaml . Controls . NavigationViewDisplayMode . Expanded )
269+ if ( NavigationViewControl . DisplayMode == NavigationViewDisplayMode . Expanded )
253270 {
254271 controlsSearchBox . Focus ( FocusState . Keyboard ) ;
255272 }
@@ -261,7 +278,7 @@ private void OnNavigationViewControlLoaded(object sender, RoutedEventArgs e)
261278 Task . Delay ( 500 ) . ContinueWith ( _ => this . NavigationViewLoaded ? . Invoke ( ) , TaskScheduler . FromCurrentSynchronizationContext ( ) ) ;
262279 }
263280
264- private void OnNavigationViewSelectionChanged ( Microsoft . UI . Xaml . Controls . NavigationView sender , Microsoft . UI . Xaml . Controls . NavigationViewSelectionChangedEventArgs args )
281+ private void OnNavigationViewSelectionChanged ( NavigationView sender , NavigationViewSelectionChangedEventArgs args )
265282 {
266283 if ( args . IsSettingsSelected )
267284 {
@@ -554,6 +571,7 @@ private void WaitForDebuggerInvokerButton_Click(object sender, RoutedEventArgs e
554571 private static extern void DebugBreak ( ) ;
555572
556573 #endregion
574+
557575 }
558576
559577 public class NavigationRootPageArgs
0 commit comments