From bf990daf559ee8128044acfa81c18e9b64945a48 Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Tue, 28 May 2024 01:59:32 +0200 Subject: [PATCH] Fix #21968 & device test --- src/Controls/src/Core/NavigationPage/NavigationPage.cs | 4 ++++ src/Controls/src/Core/Page/Page.cs | 8 ++++---- .../Elements/NavigationPage/NavigationPageTests.cs | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Controls/src/Core/NavigationPage/NavigationPage.cs b/src/Controls/src/Core/NavigationPage/NavigationPage.cs index 9a0cc0f6bf2d..706af9c131ca 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPage.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPage.cs @@ -784,6 +784,10 @@ await Owner.SendHandlerUpdateAsync(animated, { Owner.RemoveFromInnerChildren(currentPage); Owner.CurrentPage = newCurrentPage; + if (currentPage.TitleView != null) + { + currentPage.RemoveLogicalChild(currentPage.TitleView); + } }, () => { diff --git a/src/Controls/src/Core/Page/Page.cs b/src/Controls/src/Core/Page/Page.cs index 622e960087ba..bc49235eccba 100644 --- a/src/Controls/src/Core/Page/Page.cs +++ b/src/Controls/src/Core/Page/Page.cs @@ -74,7 +74,7 @@ public partial class Page : VisualElement, ILayout, IPageController, IElementCon bool _hasAppeared; private protected bool HasAppeared => _hasAppeared; - View _titleView; + internal View TitleView; List _pendingActions = new List(); @@ -494,8 +494,8 @@ protected override void OnBindingContextChanged() SetInheritedBindingContext(menubarItem, BindingContext); } - if (_titleView != null) - SetInheritedBindingContext(_titleView, BindingContext); + if (TitleView != null) + SetInheritedBindingContext(TitleView, BindingContext); } /// @@ -798,7 +798,7 @@ public IPlatformElementConfiguration On() where T : IConfigPlatform internal void SetTitleView(View oldTitleView, View newTitleView) { - _titleView = newTitleView; + TitleView = newTitleView; } internal bool HasNavigatedTo { get; private set; } diff --git a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs index eb4487f09bae..ab675465a492 100644 --- a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs @@ -332,6 +332,7 @@ await CreateHandlerAndAddToWindow(new Window(navPage), async new RadioButton(), } }; + NavigationPage.SetTitleView(page, new Label() { Text = "Title View" }); pageReference = new WeakReference(page); await navPage.Navigation.PushAsync(page); await navPage.Navigation.PopAsync();