Skip to content

refactor: NavigationViewEx property change logic and simplify control#780

Open
United600 wants to merge 12 commits intomainfrom
United600/nav-view
Open

refactor: NavigationViewEx property change logic and simplify control#780
United600 wants to merge 12 commits intomainfrom
United600/nav-view

Conversation

@United600
Copy link
Collaborator

@United600 United600 commented Feb 11, 2026

  • Consolidates dependency property change callbacks
  • Removes unnecessary SettingsItemStyle dependency property
  • Improves content grid animation translation offset
  • Initializes collections in the constructor, following the documentation
  • Adds StyleTypedPropertyAttribute to buttons style for proper suggestions

Without StyleTypedPropertyAttribute

Gravacao.2026-03-05.135312.mp4

With StyleTypedPropertyAttribute

Gravacao.2026-03-05.135125.mp4

@United600 United600 requested a review from Copilot February 11, 2026 18:14
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 11, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the NavigationViewEx control to consolidate dependency property change callbacks and improve code maintainability. The changes follow an established pattern in the codebase (as seen in ErrorInfo control) and simplify the property change handling logic.

Changes:

  • Consolidated all dependency property change callbacks into a single OnPropertyChanged method with property equality checks
  • Removed the unused SettingsItemStyle dependency property and related code
  • Improved content grid animation translation offset calculation to use actual dimensions instead of hardcoded values

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
Screenbox/Controls/NavigationViewEx.cs Implements consolidated property change handler, removes SettingsItemStyle usage, updates animation offset calculation to use actual grid dimensions, and improves overlay initialization logic
Screenbox/Controls/NavigationViewEx.Properties.cs Replaces individual property change callbacks with single consolidated callback and removes SettingsItemStyle property definition

{
_contentGrid.Visibility = visibility;
_contentGrid.Visibility = ContentVisibility;
UpdateContentGridAnimations();
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateContentGridAnimations() is now called every time ContentVisibility changes (via line 372), which is a new behavior introduced by this refactoring. Previously, it was only called during OnApplyTemplate() and when ContentAnimationDirection changed. Since the animations themselves don't depend on the current visibility state (only on ContentAnimationDirection), calling this method on every visibility change may be unnecessary and could impact performance if visibility changes frequently. Consider whether this call should be removed from UpdateContentVisibility() and only kept in the ContentAnimationDirectionProperty change handler.

Suggested change
UpdateContentGridAnimations();

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It ensures we get the correct dimensions whenever visibility changes.

// We use the ContentGrid LightDismissLayer rectangle fill to avoid tracking
// LightDismissOverlayMode, theme and high contrast changes ourselves.
if (_splitView?.FindDescendant<Rectangle>(r => r.Name == "LightDismissLayer") is Rectangle contentRootRect)
if (_splitView?.FindDescendant<Rectangle>(r => r.Name.Equals("LightDismissLayer", StringComparison.Ordinal)) is { } contentRootRect)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition is always not null because of ... != ....

Copilot uses AI. Check for mistakes.
Comment on lines +334 to +359
if (property == OverlayProperty)
{
LoadOverlay();
}
else if (property == OverlayZIndexProperty)
{
UpdateOverlayZIndex();
}
else if (property == ContentVisibilityProperty)
{
UpdateContentVisibility();
UpdateOverlayLayout();
}
else if (property == BackButtonStyleProperty)
{
UpdateBackButtonStyle();
UpdateCloseButtonStyle();
}
else if (property == PaneSearchButtonStyleProperty)
{
UpdatePaneSearchButtonStyle();
}
else if (property == ContentAnimationDirectionProperty)
{
UpdateContentGridAnimations();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a perfect opportunity for a switch statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try it, but it wasn't the most readable block of code. I can give it another go.

Copy link
Collaborator Author

@United600 United600 Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, the if/else chain seems like the cleaner and more straightforward solution, and it's a clear improvement over the previous implementation. I can't seem to find a switch statement syntax that feels satisfying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants