diff --git a/Xamarin.Forms.Platform.UAP/Shell/ShellRenderer.cs b/Xamarin.Forms.Platform.UAP/Shell/ShellRenderer.cs index 201f203bf83..51d8a32a5ac 100644 --- a/Xamarin.Forms.Platform.UAP/Shell/ShellRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/Shell/ShellRenderer.cs @@ -38,12 +38,6 @@ public ShellRenderer() IsPaneOpen = false; Content = ItemRenderer = CreateShellItemRenderer(); MenuItemTemplateSelector = CreateShellFlyoutTemplateSelector(); - if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneClosing")) - PaneClosing += (s, e) => OnPaneClosed(); - if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneOpening")) - PaneOpening += (s, e) => OnPaneOpening(); - ItemInvoked += OnMenuItemInvoked; - BackRequested += OnBackRequested; Style = Windows.UI.Xaml.Application.Current.Resources["ShellNavigationView"] as Windows.UI.Xaml.Style; } @@ -72,20 +66,25 @@ protected override void OnApplyTemplate() UpdatePaneButtonColor(NavigationViewBackButton, !IsPaneOpen); } - void OnPaneOpening() + void OnPaneOpening(Microsoft.UI.Xaml.Controls.NavigationView sender, object args) { if (Shell != null) Shell.FlyoutIsPresented = true; + UpdatePaneButtonColor(TogglePaneButton, false); UpdatePaneButtonColor(NavigationViewBackButton, false); UpdateFlyoutBackgroundColor(); UpdateFlyoutBackdrop(); + } - if(_flyoutBehavior == FlyoutBehavior.Flyout) - ShellSplitView.UpdateFlyoutBackdrop(); + void OnPaneOpened(Microsoft.UI.Xaml.Controls.NavigationView sender, object args) + { + // UWP likes to sometimes set the back drop back to the + // default color + UpdateFlyoutBackdrop(); } - void OnPaneClosed() + void OnPaneClosing(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewPaneClosingEventArgs args) { if (Shell != null) Shell.FlyoutIsPresented = false; @@ -147,6 +146,18 @@ public void SetElement(VisualElement element) if (element != null) { + + if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneClosing")) + PaneClosing += OnPaneClosing; + if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneOpening")) + PaneOpening += OnPaneOpening; + if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneOpened")) + PaneOpened += OnPaneOpened; + + ItemInvoked += OnMenuItemInvoked; + BackRequested += OnBackRequested; + + Element = (Shell)element; Element.SizeChanged += OnElementSizeChanged; OnElementSet(Element); @@ -158,12 +169,20 @@ public void SetElement(VisualElement element) { Element.SizeChanged -= OnElementSizeChanged; Element.PropertyChanged -= OnElementPropertyChanged; + + if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneClosing")) + PaneClosing -= OnPaneClosing; + if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneOpening")) + PaneOpening -= OnPaneOpening; + if (ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.NavigationView", "PaneOpened")) + PaneOpened -= OnPaneOpened; + + ItemInvoked -= OnMenuItemInvoked; + BackRequested -= OnBackRequested; } } #endregion IVisualElementRenderer - - ShellSplitView ShellSplitView => (ShellSplitView)GetTemplateChild("RootSplitView"); protected internal Shell Element { get; set; }