Skip to content

Fix HeaderContent not respecting bindings. #1415

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vegardlarsen
Copy link

@vegardlarsen vegardlarsen commented Apr 15, 2025

This commit fixes a bug that occurs if you use a binding with ui:NavigationView.HeaderContent when the DataContext is passed in through navigation.

This particularly affects multi-level navigation when you add the DataContext to the navigation, effectively preventing the correct titles from being rendered as breadcrumb titles.

Pull request type

Please check the type of change your PR introduces:

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

What is the current behavior?

In a multi-level navigation scenario, when navigating using INavigationService.NavigateWithHierarchy() (and passing a data context), if you then try to bind any value from the DataContext to wpfui:NavigationView.HeaderContent, the binding will fail to work on the first page load.

If you navigate back and forward, the breadcrumbs will update with the previous value of the binding.

Issue Number: #889 (possibly related)

What is the new behavior?

This PR does changes several things to achieve the goal of being able to bind to NavigationView.HeaderContent.

  1. Turns NavigationViewBreadcrumbItem into DependencyObject, and adds a ContentProperty dependency property to be able to react to updates.
  2. Adds a dictionary to NavigationView to build a map between Pages and INavigationViewItems. This allows it to look up INavigationViewItems when a new value is assigned to NavigationView.HeaderContent.
  3. Changes the order of ApplyAttachedProperties and UpdateContent, so the DataContext is available before the HeaderContent.
  4. Sets NavigationParentProperty for any Page that gets navigated to, so HeaderContent can look up which NavigationView to notify about its content changing.

Other information

I have a reproduction of this issue in a separate -- but relatively large -- project, and I have been testing this fix against that project. I was uncertain of how to provide a reproduction in this repository, and I have therefore not included it yet. I would be happy to add one if necessary.

I am also not an expert in WPF, and have therefore used an LLM to help me understand the intricacies of this code, but all code in this PR was written by me. I have a feeling that there may be a simpler method to resolving this issue, but I have failed to find it.

This commit fixes a bug that occurs if you use a binding with `ui:NavigationView.HeaderContent` when the `DataContext` is passed in through navigation.

This particularly affects multi-level navigation when you add the DataContext to the navigation, effectively preventing the correct titles from being rendered as breadcrumb titles.
@github-actions github-actions bot added controls Changes to the appearance or logic of custom controls. PR Pull request navigation Changes to navigation related controls. dotnet release labels Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controls Changes to the appearance or logic of custom controls. dotnet navigation Changes to navigation related controls. PR Pull request release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant