Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Set Backdrop Color after Pane Opened #12099

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions Xamarin.Forms.Platform.UAP/Shell/ShellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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; }

Expand Down