diff --git a/src/Controls/src/Core/TabbedPage/TabbedPage.Windows.cs b/src/Controls/src/Core/TabbedPage/TabbedPage.Windows.cs
index d26a2a4de133..f0512f5ef849 100644
--- a/src/Controls/src/Core/TabbedPage/TabbedPage.Windows.cs
+++ b/src/Controls/src/Core/TabbedPage/TabbedPage.Windows.cs
@@ -134,7 +134,10 @@ void OnHandlerDisconnected(FrameworkElement? platformView)
Appearing -= OnTabbedPageAppearing;
Disappearing -= OnTabbedPageDisappearing;
if (_navigationView != null)
+ {
+ _navigationView.SelectedItem = null;
_navigationView.SelectionChanged -= OnSelectedMenuItemChanged;
+ }
OnTabbedPageDisappearing(this, EventArgs.Empty);
@@ -331,6 +334,7 @@ internal static void MapItemsSource(ITabbedViewHandler handler, TabbedPage view)
vm.UnselectedTitleColor = view.BarTextColor?.AsPaint()?.ToPlatform();
vm.SelectedForeground = view.SelectedTabColor?.AsPaint()?.ToPlatform();
vm.UnselectedForeground = view.UnselectedTabColor?.AsPaint()?.ToPlatform();
+ vm.IsSelected = page == view.CurrentPage;
});
handler.UpdateValue(nameof(TabbedPage.CurrentPage));
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24741.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24741.cs
new file mode 100644
index 000000000000..6745d5f011aa
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24741.cs
@@ -0,0 +1,36 @@
+namespace Maui.Controls.Sample.Issues
+{
+ [Issue(IssueTracker.Github, 24741, "Unable to select tab after backing out of page and returning", PlatformAffected.UWP)]
+ public class Issue24741 : NavigationPage
+ {
+ public Issue24741() : base(new TestPage())
+ {
+ }
+
+ public class TestPage : TestContentPage
+ {
+ protected override void Init()
+ {
+ Title = "Issue 24741";
+
+ var navigationButton = new Button
+ {
+ AutomationId = "NavigateButton",
+ Text = "Navigate to TabbedPage"
+ };
+
+ navigationButton.Clicked += (s, e) =>
+ {
+ Navigation.PushAsync(new Issue24741TabbedPage());
+ };
+
+ var content = new VerticalStackLayout
+ {
+ navigationButton
+ };
+
+ Content = content;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24741TabbedPage.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue24741TabbedPage.xaml
new file mode 100644
index 000000000000..fd1e473d4827
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24741TabbedPage.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24741TabbedPage.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24741TabbedPage.xaml.cs
new file mode 100644
index 000000000000..125fd43a7022
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24741TabbedPage.xaml.cs
@@ -0,0 +1,57 @@
+namespace Maui.Controls.Sample.Issues;
+
+public partial class Issue24741TabbedPage : TabbedPage
+{
+ public Issue24741TabbedPage()
+ {
+ InitializeComponent();
+ }
+}
+
+public class Issue24741Page1 : ContentPage
+{
+ public Issue24741Page1()
+ {
+ Title = "Page 1";
+
+ var content = new Button
+ {
+ AutomationId = "Page1Button",
+ Text = "Page 1"
+ };
+
+ content.Clicked += async (sender, args) =>
+ {
+ await Navigation.PopAsync();
+ };
+
+ Content = new VerticalStackLayout
+ {
+ content
+ };
+ }
+}
+
+public class Issue24741Page2 : ContentPage
+{
+ public Issue24741Page2()
+ {
+ Title = "Page 2";
+
+ var content = new Button
+ {
+ AutomationId = "Page2Button",
+ Text = "Page 2"
+ };
+
+ content.Clicked += async (sender, args) =>
+ {
+ await Navigation.PopAsync();
+ };
+
+ Content = new VerticalStackLayout
+ {
+ content
+ };
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24741.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24741.cs
new file mode 100644
index 000000000000..7deb38e6f347
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24741.cs
@@ -0,0 +1,46 @@
+#if WINDOWS
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues
+{
+ public class Issue24741 : _IssuesUITest
+ {
+ public Issue24741(TestDevice testDevice) : base(testDevice)
+ {
+ }
+
+ public override string Issue => "Unable to select tab after backing out of page and returning";
+
+ [Test]
+ [Category(UITestCategories.TabbedPage)]
+ public void SelectTabAfterNavigation()
+ {
+ const string Page2Title = "Page 2";
+
+ // 1. Navigate to the TabbedPage.
+ App.WaitForElement("NavigateButton");
+ App.Tap("NavigateButton");
+
+ // 2. Click the second Tab.
+ App.Tap(Page2Title);
+
+ // 3. Navigate back.
+ App.WaitForElement("Page2Button");
+ App.Tap("Page2Button");
+
+ // 4. Repeat the process. Navigate to the TabbedPage.
+ App.WaitForElement("NavigateButton");
+ App.Tap("NavigateButton");
+
+ // 2. Click the second Tab.
+ App.Tap(Page2Title);
+
+ // 6. Screenshot to validate the result.
+ VerifyScreenshot();
+ App.Back();
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SelectTabAfterNavigation.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SelectTabAfterNavigation.png
new file mode 100644
index 000000000000..d1b8e55a0818
Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/SelectTabAfterNavigation.png differ
diff --git a/src/Core/src/Platform/Windows/NavigationViewItemViewModel.cs b/src/Core/src/Platform/Windows/NavigationViewItemViewModel.cs
index 515f6c310479..1e75aadd1776 100644
--- a/src/Core/src/Platform/Windows/NavigationViewItemViewModel.cs
+++ b/src/Core/src/Platform/Windows/NavigationViewItemViewModel.cs
@@ -214,6 +214,7 @@ public bool IsSelected
{
_isSelected = value;
OnPropertyChanged(nameof(Background));
+ OnPropertyChanged(nameof(TitleColor));
UpdateForeground();
}
}
diff --git a/src/TestUtils/src/UITest.Appium/AppiumApp.cs b/src/TestUtils/src/UITest.Appium/AppiumApp.cs
index b947159cfba1..6e6c2014ce69 100644
--- a/src/TestUtils/src/UITest.Appium/AppiumApp.cs
+++ b/src/TestUtils/src/UITest.Appium/AppiumApp.cs
@@ -90,7 +90,8 @@ public virtual IUIElement FindElement(IQuery query)
#nullable disable
public virtual IUIElement FindElementByText(string text)
{
- return AppiumQuery.ByXPath("//*[@text='" + text + "' or @Name='" + text + "']").FindElement(this);
+ // Android (text), iOS (label), Windows (Name)
+ return AppiumQuery.ByXPath("//*[@text='" + text + "' or @label='" + text + "' or @Name='" + text + "']").FindElement(this);
}
#nullable enable
@@ -101,7 +102,8 @@ public virtual IReadOnlyCollection FindElements(string id)
public virtual IReadOnlyCollection FindElementsByText(string text)
{
- return AppiumQuery.ByXPath("//*[@text='" + text + "' or @Name='" + text + "']").FindElements(this);
+ // Android (text), iOS (label), Windows (Name)
+ return AppiumQuery.ByXPath("//*[@text='" + text + "' or @label='" + text + "' or @Name='" + text + "']").FindElements(this);
}
public virtual IReadOnlyCollection FindElements(IQuery query)