-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix Shell.Title binding in TitleView #35800
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,27 +169,47 @@ internal void UpdateTitle() | |
| Shell.TitleViewProperty, | ||
| Shell.GetTitleView(_shell)); | ||
|
|
||
| var title = GetCurrentTitle(); | ||
| if (!IsShellTitleSetByUser()) | ||
| _shell.SetValueFromRenderer(Shell.TitleProperty, title); | ||
|
|
||
| if (TitleView != null) | ||
| { | ||
| Title = String.Empty; | ||
| return; | ||
| } | ||
|
|
||
| Title = title; | ||
| } | ||
|
|
||
| string GetCurrentTitle() | ||
| { | ||
| Page? currentPage = _shell.GetCurrentShellPage(); | ||
| if (currentPage?.IsSet(Page.TitleProperty) == true) | ||
| { | ||
| Title = currentPage.Title ?? String.Empty; | ||
| return currentPage.Title ?? String.Empty; | ||
| } | ||
| // We only want to use the ShellContent as a title if no pages have been | ||
| // Pushed onto the stack | ||
| else if (_shell.Navigation?.NavigationStack?.Count <= 1) | ||
| { | ||
| Title = _shell.CurrentContent?.Title ?? String.Empty; | ||
| } | ||
| else | ||
| { | ||
| Title = String.Empty; | ||
| return _shell.CurrentContent?.Title ?? String.Empty; | ||
| } | ||
|
|
||
| return String.Empty; | ||
| } | ||
|
|
||
| bool IsShellTitleSetByUser() | ||
| { | ||
| var titleContext = _shell.GetContext(Shell.TitleProperty); | ||
| if (titleContext == null) | ||
| return false; | ||
|
|
||
| if (titleContext.Bindings.Count > 0) | ||
| return true; | ||
|
|
||
| var specificity = titleContext.Values.GetSpecificity(); | ||
| return specificity != SetterSpecificity.DefaultValue && specificity != SetterSpecificity.FromHandler; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ [major] Navigation & Shell — This treats
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you fix it? |
||
| } | ||
| } | ||
| } | ||
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.
[major] Logic and Correctness — This still treats an explicit TwoWay binding on
Shell.Titleas handler-owned state and overwrites it with the current page title.BindableObject.SetBindingstores TwoWay bindings withSetterSpecificity.FromHandler, soIsShellTitleSetByUser()returns false for<Shell Title="{Binding AppTitle, Mode=TwoWay}">; when a TitleView is applied or the page title changes, this line pushes the page title intoShell.Titleand back into the view model instead of preserving the app's binding. Please distinguish an actual binding in the property context from renderer-generated title values before callingSetValueFromRenderer.