From 993af285de1a0e3ee483d1c4204032e83d7d2e0b Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Wed, 26 Mar 2025 00:44:55 +0100 Subject: [PATCH 1/2] Propagate BackButtonBehaviorProperty --- .../src/Core/Internals/PropertyPropagationExtensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs b/src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs index d0ae6c9aa3f0..4e5c0d10dd8b 100644 --- a/src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs +++ b/src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs @@ -40,6 +40,9 @@ internal static void PropagatePropertyChanged(string propertyName, Element eleme if (propertyName == null || propertyName == Shell.NavBarVisibilityAnimationEnabledProperty.PropertyName) BaseShellItem.PropagateFromParent(Shell.NavBarVisibilityAnimationEnabledProperty, element); + + if (propertyName == null || propertyName == Shell.BackButtonBehaviorProperty.PropertyName) + BaseShellItem.PropagateFromParent(Shell.BackButtonBehaviorProperty, element); foreach (var child in children.ToArray()) { From bb761c3163e1d5863810bd1c4a825b518b4c5d6c Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Wed, 26 Mar 2025 16:04:27 +0100 Subject: [PATCH 2/2] Added a UITest --- .../TestCases.HostApp/Issues/Issue28570.cs | 56 +++++++++++++++++++ .../Tests/Issues/Issue28570.cs | 23 ++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue28570.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28570.cs diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue28570.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue28570.cs new file mode 100644 index 000000000000..e06b2fae2402 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue28570.cs @@ -0,0 +1,56 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 28570, "Setting BackButtonBehavior to not visible or not enabled does not work")] +public class Issue28570 : Shell +{ + public Issue28570() + { + // Register the routes + Routing.RegisterRoute("Issue28570DetailPage", typeof(Issue28570DetailPage)); + + ContentPage contentPage = new ContentPage + { + Title = "Main Page", + Content = new Button + { + Text = "Go to Detail Page", + AutomationId = "NavigateToDetailButton", + Command = new Command(async () => await Shell.Current.GoToAsync("Issue28570DetailPage")) + } + }; + + BackButtonBehavior backButtonBehavior = new BackButtonBehavior + { + IsVisible = false, + TextOverride = "BackButton" + }; + + SetBackButtonBehavior(this, backButtonBehavior); + + // Create and add Shell contents + var page1 = new ShellContent + { + Title = "Page 1", + Content = contentPage + }; + + Items.Add(page1); + } +} + +public class Issue28570DetailPage : ContentPage +{ + public Issue28570DetailPage() + { + Title = "Detail page"; + + Content = new VerticalStackLayout() + { + new Label() + { + AutomationId = "HelloLabel", + Text = "Hello, from the detail page", + } + }; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28570.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28570.cs new file mode 100644 index 000000000000..b3602174e497 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28570.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue28570 : _IssuesUITest +{ + public Issue28570(TestDevice testDevice) : base(testDevice) { } + + public override string Issue => "Setting BackButtonBehavior to not visible or not enabled does not work"; + + [Test] + [Category(UITestCategories.Shell)] + [Category(UITestCategories.Navigation)] + public void BackButtonShouldNotBeVisible() + { + App.WaitForElement("NavigateToDetailButton"); + App.Click("NavigateToDetailButton"); + App.WaitForElement("HelloLabel"); + App.WaitForNoElement("BackButton"); + } +} \ No newline at end of file