Fix HeaderContent not respecting bindings. #1415
Open
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.
This commit fixes a bug that occurs if you use a binding with
ui:NavigationView.HeaderContent
when theDataContext
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:
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 theDataContext
towpfui: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
.NavigationViewBreadcrumbItem
intoDependencyObject
, and adds aContentProperty
dependency property to be able to react to updates.NavigationView
to build a map betweenPage
s andINavigationViewItem
s. This allows it to look upINavigationViewItem
s when a new value is assigned toNavigationView.HeaderContent
.ApplyAttachedProperties
andUpdateContent
, so theDataContext
is available before theHeaderContent
.NavigationParentProperty
for anyPage
that gets navigated to, soHeaderContent
can look up whichNavigationView
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.