Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port microsoft/microsoft-ui-xaml#4779 #653

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
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
65 changes: 35 additions & 30 deletions ModernWpf.Controls/NavigationView/NavigationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public partial class NavigationView : ContentControl, IControlProtected
const int c_toggleButtonHeightWhenShouldPreserveNavigationViewRS3Behavior = 56;
const int c_backButtonRowDefinition = 1;
const float c_paneElevationTranslationZ = 32;
const int c_paneItemsSeparatorHeight = 21;
const int c_paneItemsSeparatorHeight = 9;

const int c_mainMenuBlockIndex = 0;
const int c_footerMenuBlockIndex = 1;
Expand Down Expand Up @@ -756,6 +756,7 @@ public override void OnApplyTemplate()
UpdateVisualState();
UpdatePaneTitleMargins();
UpdatePaneLayout();
UpdatePaneOverlayGroup();
}

void UpdateRepeaterItemsSource(bool forceSelectionModelUpdate)
Expand Down Expand Up @@ -1572,7 +1573,7 @@ double ItemsContainerMargin()
}
var availableHeight = paneContentRow.ActualHeight - itemsContainerMargin;

// The -21 below is to account for the separator height that we need to subtract.
// The c_paneItemsSeparatorHeight is to account for the 9px separator height that we need to subtract.
if (PaneFooter is { })
{
availableHeight -= c_paneItemsSeparatorHeight;
Expand Down Expand Up @@ -1811,8 +1812,6 @@ void OnSplitViewPaneClosing(DependencyObject sender, SplitViewPaneClosingEventAr
VisualStateManager.GoToState(this, "ListSizeCompact", true /*useTransitions*/);
UpdatePaneToggleSize();
}

VisualStateManager.GoToState(this, "PaneNotOverlaying", true /*useTransitions*/);
}
}
}
Expand All @@ -1829,14 +1828,6 @@ void OnSplitViewPaneOpening(DependencyObject sender, object obj)
{
// See UpdateIsClosedCompact 'RS3+ animation timing enhancement' for explanation:
VisualStateManager.GoToState(this, "ListSizeFull", true /*useTransitions*/);

if (m_rootSplitView is { } splitView)
{
if (splitView.DisplayMode == SplitViewDisplayMode.CompactOverlay || splitView.DisplayMode == SplitViewDisplayMode.Overlay)
{
VisualStateManager.GoToState(this, "PaneOverlaying", true /*useTransitions*/);
}
}
}

PaneOpening?.Invoke(this, null);
Expand Down Expand Up @@ -2008,20 +1999,25 @@ void UpdatePaneTitleFrameworkElementParents()
{
var isPaneToggleButtonVisible = IsPaneToggleButtonVisible;
var isTopNavigationView = IsTopNavigationView();
var paneTitleSize = PaneTitle?.Length ?? 0;

m_isLeftPaneTitleEmpty = (isPaneToggleButtonVisible ||
isTopNavigationView ||
paneTitleSize == 0 ||
(PaneDisplayMode == NavigationViewPaneDisplayMode.LeftMinimal && !IsPaneOpen));

paneTitleHolderFrameworkElement.Visibility =
(isPaneToggleButtonVisible ||
isTopNavigationView ||
PaneTitle.Length == 0 ||
(PaneDisplayMode == NavigationViewPaneDisplayMode.LeftMinimal && !IsPaneOpen)) ?
Visibility.Collapsed : Visibility.Visible;
paneTitleHolderFrameworkElement.Visibility = m_isLeftPaneTitleEmpty ? Visibility.Collapsed : Visibility.Visible;

if (m_paneTitleFrameworkElement is { } paneTitleFrameworkElement)
{
var paneTitleTopPane = m_paneTitleOnTopPane;

var first = SetPaneTitleFrameworkElementParent(m_paneToggleButton, paneTitleFrameworkElement, isTopNavigationView || !isPaneToggleButtonVisible);
var second = SetPaneTitleFrameworkElementParent(m_paneTitlePresenter, paneTitleFrameworkElement, isTopNavigationView || isPaneToggleButtonVisible);
var third = SetPaneTitleFrameworkElementParent(m_paneTitleOnTopPane, paneTitleFrameworkElement, !isTopNavigationView || isPaneToggleButtonVisible);
var third = SetPaneTitleFrameworkElementParent(paneTitleTopPane, paneTitleFrameworkElement, !isTopNavigationView || isPaneToggleButtonVisible);
(first ?? second ?? third)?.Invoke();

paneTitleTopPane.Visibility = third is { } && paneTitleSize != 0 ? Visibility.Visible : Visibility.Collapsed;
}
}
}
Expand Down Expand Up @@ -3559,7 +3555,7 @@ void UpdateVisualStateForOverflowButton()
void UpdateLeftNavigationOnlyVisualState(bool useTransitions)
{
bool isToggleButtonVisible = IsPaneToggleButtonVisible;
VisualStateManager.GoToState(this, isToggleButtonVisible ? "TogglePaneButtonVisible" : "TogglePaneButtonCollapsed", false /*useTransitions*/);
VisualStateManager.GoToState(this, isToggleButtonVisible || !m_isLeftPaneTitleEmpty ? "TogglePaneButtonVisible" : "TogglePaneButtonCollapsed", false /*useTransitions*/);
}

void InvalidateTopNavPrimaryLayout()
Expand Down Expand Up @@ -4296,6 +4292,8 @@ void OnIsPaneOpenChanged()
UpdatePaneTabFocusNavigation();
UpdateSettingsItemToolTip();
UpdatePaneTitleFrameworkElementParents();
UpdatePaneOverlayGroup();
UpdatePaneButtonsWidths();

if (SharedHelpers.IsThemeShadowAvailable())
{
Expand All @@ -4313,7 +4311,6 @@ void OnIsPaneOpenChanged()
}
}
}
UpdatePaneButtonsWidths();
}

void UpdatePaneToggleButtonVisibility()
Expand Down Expand Up @@ -4655,15 +4652,6 @@ void UpdateBackAndCloseButtonsVisibility()
paneHeaderCloseButtonColumn.Width = GridLengthHelper.FromValueAndType(paneHeaderPaddingForCloseButton, GridUnitType.Pixel);
}

if (m_paneTitleHolderFrameworkElement is { } paneTitleHolderFrameworkElement)
{
if (paneHeaderContentBorderRowMinHeight == 0.00 && paneTitleHolderFrameworkElement.Visibility == Visibility.Visible)
{
// Handling the case where the PaneTottleButton is collapsed and the PaneTitle's height needs to push the rest of the NavigationView's UI down.
paneHeaderContentBorderRowMinHeight = paneTitleHolderFrameworkElement.ActualHeight;
}
}

if (m_paneHeaderContentBorderRow is { } paneHeaderContentBorderRow)
{
paneHeaderContentBorderRow.MinHeight = paneHeaderContentBorderRowMinHeight;
Expand Down Expand Up @@ -5027,6 +5015,21 @@ void UpdatePaneShadow()
*/
}

void UpdatePaneOverlayGroup()
{
if (m_rootSplitView is { } splitView)
{
if (IsPaneOpen && (splitView.DisplayMode == SplitViewDisplayMode.CompactOverlay || splitView.DisplayMode == SplitViewDisplayMode.Overlay))
{
VisualStateManager.GoToState(this, "PaneOverlaying", true /*useTransitions*/);
}
else
{
VisualStateManager.GoToState(this, "PaneNotOverlaying", true /*useTransitions*/);
}
}
}

T GetContainerForData<T>(object data) where T : class
{
if (data == null)
Expand Down Expand Up @@ -5870,6 +5873,8 @@ protected override void OnDpiChanged(DpiScale oldDpi, DpiScale newDpi)

bool m_TabKeyPrecedesFocusChange = false;

bool m_isLeftPaneTitleEmpty = false;

GettingFocusHelper m_leftNavRepeaterGettingFocusHelper;
GettingFocusHelper m_topNavRepeaterGettingFocusHelper;
GettingFocusHelper m_leftNavFooterMenuRepeaterGettingFocusHelper;
Expand Down
Loading
Loading