diff --git a/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs b/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs index 6e6305fdab80..b2569e7c9c57 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs @@ -158,9 +158,9 @@ void UpdateBackButton() // Once we have better logic inside core to handle backbutton visiblity this // code should all go away. - // Windows currently doesn't have logic in core to handle back button visibility + // Windows currently doesn't have logic in core to handle back button visibility // Android just handles it as part of core which means you get cool animations - // that we don't want to interrupt here. + // that we don't want to interrupt here. // Once it's all built into core we can remove this code and simplify visibility logic if (_currentPage.IsSet(NavigationPage.HasBackButtonProperty)) { @@ -273,7 +273,16 @@ void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEvent Color GetBarTextColor() => _currentNavigationPage?.BarTextColor; Color GetIconColor() => (_currentPage != null) ? NavigationPage.GetIconColor(_currentPage) : null; - string GetTitle() => GetTitleView() != null ? String.Empty : _currentPage?.Title; + + string GetTitle() + { + if (GetTitleView() != null) + { + return string.Empty; + } + + return _currentNavigationPage?.CurrentPage?.Title; + } VisualElement GetTitleView() { diff --git a/src/Controls/tests/Core.UnitTests/ToolbarTests.cs b/src/Controls/tests/Core.UnitTests/ToolbarTests.cs index 6b903c9542b4..e1c28a847032 100644 --- a/src/Controls/tests/Core.UnitTests/ToolbarTests.cs +++ b/src/Controls/tests/Core.UnitTests/ToolbarTests.cs @@ -56,6 +56,22 @@ public async Task TitleAndTitleViewAreMutuallyExclusive() Assert.Equal("Test Title", toolbar.Title); } + [Fact] + public void ToolbarTitle_UsesTabbedPageTitleWhenSet() + { + var window = new TestWindow(); + IToolbarElement toolbarElement = window; + var tabbedPage = new TabbedPage + { + Title = "Test Title", + Children = { new ContentPage { Title = "Child Test Title" } }, + }; + window.Page = new NavigationPage(tabbedPage); + + var toolbar = (Toolbar)toolbarElement.Toolbar; + Assert.Equal(tabbedPage.Title, toolbar.Title); + } + [Fact] public async Task InsertPageBeforeRootPageShowsBackButton() { diff --git a/src/Controls/tests/DeviceTests/Elements/Toolbar/ToolbarTests.cs b/src/Controls/tests/DeviceTests/Elements/Toolbar/ToolbarTests.cs index b5e2d1ff7e6b..57cce7a46c29 100644 --- a/src/Controls/tests/DeviceTests/Elements/Toolbar/ToolbarTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Toolbar/ToolbarTests.cs @@ -19,6 +19,7 @@ #if IOS || MACCATALYST using FlyoutViewHandler = Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer; using NavigationViewHandler = Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer; +using TabbedRenderer = Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer; #endif namespace Microsoft.Maui.DeviceTests @@ -38,7 +39,11 @@ void SetupBuilder() handlers.AddHandler(typeof(Controls.NavigationPage), typeof(NavigationViewHandler)); handlers.AddHandler(); handlers.AddHandler(); - handlers.AddHandler(typeof(TabbedPage), typeof(TabbedViewHandler)); + #if IOS || MACCATALYST + handlers.AddHandler(typeof(TabbedPage), typeof(TabbedRenderer)); +#else + handlers.AddHandler(typeof(TabbedPage), typeof(TabbedViewHandler)); +#endif SetupShellHandlers(handlers); });