-
-
Notifications
You must be signed in to change notification settings - Fork 77
[Enhancement] NavigationViewItem #267
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
Open
mou-haz
wants to merge
3
commits into
iNKORE-NET:main
Choose a base branch
from
mou-haz:fix_83
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ public override void OnApplyTemplate() | |
| { | ||
| // Stop UpdateVisualState before template is applied. Otherwise the visuals may be unexpected | ||
| m_appliedTemplate = false; | ||
| m_restoreToExpandedState = false; | ||
|
|
||
| UnhookEventsAndClearFields(); | ||
|
|
||
|
|
@@ -203,6 +204,7 @@ void OnSplitViewPropertyChanged(DependencyObject sender, DependencyProperty args | |
| { | ||
| UpdateIsClosedCompact(); | ||
| ReparentRepeater(); | ||
| HandleExpansionStateMemory(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -237,6 +239,25 @@ internal void UpdateIsClosedCompact() | |
| } | ||
| } | ||
|
|
||
| private void HandleExpansionStateMemory() | ||
| { | ||
| if (IsTopLevelItem) | ||
| { | ||
| var splitView = GetSplitView(); | ||
| if (splitView != null) | ||
| { | ||
| if (splitView.IsPaneOpen) | ||
| { | ||
| RestoreExpandedState(); | ||
| } | ||
| else | ||
| { | ||
| ForceCollapse(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void UpdateNavigationViewItemToolTip() | ||
| { | ||
| var toolTipContent = ToolTipService.GetToolTip(this); | ||
|
|
@@ -283,6 +304,8 @@ void SuggestedToolTipChanged(object newContent) | |
|
|
||
| void OnIsExpandedPropertyChanged(DependencyPropertyChangedEventArgs args) | ||
| { | ||
| m_restoreToExpandedState = false; | ||
|
|
||
| if (FrameworkElementAutomationPeer.FromElement(this) is AutomationPeer peer) | ||
| { | ||
| var navViewItemPeer = (NavigationViewItemAutomationPeer)peer; | ||
|
|
@@ -292,6 +315,8 @@ void OnIsExpandedPropertyChanged(DependencyPropertyChangedEventArgs args) | |
| ExpandCollapseState.Collapsed | ||
| ); | ||
| } | ||
|
|
||
| UpdateVisualState(true); | ||
| } | ||
|
|
||
| void OnIconPropertyChanged(DependencyPropertyChangedEventArgs args) | ||
|
|
@@ -342,7 +367,7 @@ void UpdateVisualStateForInfoBadge() | |
| { | ||
| if (m_navigationViewItemPresenter is { } presenter) | ||
| { | ||
| var stateName = ShouldShowInfoBadge() ? "InfoBadgeVisible" : "InfoBadgeCollapsed"; | ||
| var stateName = ShouldShowInfoBadge() ? "InfoBadgeVisible" : "InfoBadgeCollapsed"; | ||
| VisualStateManager.GoToState(presenter, stateName, false /*useTransitions*/); | ||
| } | ||
| } | ||
|
|
@@ -370,6 +395,8 @@ void UpdateVisualStateForNavigationViewPositionChange() | |
| break; | ||
| case NavigationViewRepeaterPosition.TopPrimary: | ||
| case NavigationViewRepeaterPosition.TopFooter: | ||
| m_restoreToExpandedState = false; | ||
|
|
||
|
Comment on lines
+398
to
+399
|
||
| if (SharedHelpers.IsRS4OrHigher() && false /*Application.Current.FocusVisualKind == FocusVisualKind.Reveal*/) | ||
| { | ||
| stateName = c_OnTopNavigationPrimaryReveal; | ||
|
|
@@ -381,6 +408,7 @@ void UpdateVisualStateForNavigationViewPositionChange() | |
| break; | ||
| case NavigationViewRepeaterPosition.TopOverflow: | ||
| stateName = c_OnTopNavigationOverflow; | ||
| m_restoreToExpandedState = false; | ||
| break; | ||
| } | ||
|
|
||
|
|
@@ -629,6 +657,24 @@ internal void ShowHideChildren() | |
| } | ||
| } | ||
|
|
||
| void ForceCollapse() | ||
| { | ||
| if (IsExpanded) | ||
| { | ||
| IsExpanded = false; | ||
| m_restoreToExpandedState = true; | ||
| } | ||
| } | ||
|
|
||
| void RestoreExpandedState() | ||
| { | ||
| if (m_restoreToExpandedState) | ||
| { | ||
| IsExpanded = true; | ||
| m_restoreToExpandedState = false; | ||
| } | ||
| } | ||
|
|
||
| void ReparentRepeater() | ||
| { | ||
| if (HasChildren()) | ||
|
|
@@ -966,5 +1012,9 @@ void UnhookEventsAndClearFields() | |
| bool m_isPointerOver = false; | ||
|
|
||
| bool m_isRepeaterParentedToFlyout = false; | ||
|
|
||
| // NavigationView needs to force collapse top level items when the pane closes. | ||
| // This bool is used to remember which items need to be restored to expanded state when the pane is opened again. | ||
| bool m_restoreToExpandedState = false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This
UpdateVisualState(true)call at the end ofOnIsExpandedPropertyChangedshould have a comment explaining why it's necessary here, as the visual state update may not be obvious from the context of handling expansion state changes.