Skip to content

Commit 86c038a

Browse files
authored
Shell - Propagate BackButtonBehaviorProperty (#28615)
* Propagate BackButtonBehaviorProperty * Added a UITest
1 parent f0c875a commit 86c038a

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ internal static void PropagatePropertyChanged(string propertyName, Element eleme
4040

4141
if (propertyName == null || propertyName == Shell.NavBarVisibilityAnimationEnabledProperty.PropertyName)
4242
BaseShellItem.PropagateFromParent(Shell.NavBarVisibilityAnimationEnabledProperty, element);
43+
44+
if (propertyName == null || propertyName == Shell.BackButtonBehaviorProperty.PropertyName)
45+
BaseShellItem.PropagateFromParent(Shell.BackButtonBehaviorProperty, element);
4346

4447
foreach (var child in children.ToArray())
4548
{
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 28570, "Setting BackButtonBehavior to not visible or not enabled does not work")]
4+
public class Issue28570 : Shell
5+
{
6+
public Issue28570()
7+
{
8+
// Register the routes
9+
Routing.RegisterRoute("Issue28570DetailPage", typeof(Issue28570DetailPage));
10+
11+
ContentPage contentPage = new ContentPage
12+
{
13+
Title = "Main Page",
14+
Content = new Button
15+
{
16+
Text = "Go to Detail Page",
17+
AutomationId = "NavigateToDetailButton",
18+
Command = new Command(async () => await Shell.Current.GoToAsync("Issue28570DetailPage"))
19+
}
20+
};
21+
22+
BackButtonBehavior backButtonBehavior = new BackButtonBehavior
23+
{
24+
IsVisible = false,
25+
TextOverride = "BackButton"
26+
};
27+
28+
SetBackButtonBehavior(this, backButtonBehavior);
29+
30+
// Create and add Shell contents
31+
var page1 = new ShellContent
32+
{
33+
Title = "Page 1",
34+
Content = contentPage
35+
};
36+
37+
Items.Add(page1);
38+
}
39+
}
40+
41+
public class Issue28570DetailPage : ContentPage
42+
{
43+
public Issue28570DetailPage()
44+
{
45+
Title = "Detail page";
46+
47+
Content = new VerticalStackLayout()
48+
{
49+
new Label()
50+
{
51+
AutomationId = "HelloLabel",
52+
Text = "Hello, from the detail page",
53+
}
54+
};
55+
}
56+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue28570 : _IssuesUITest
8+
{
9+
public Issue28570(TestDevice testDevice) : base(testDevice) { }
10+
11+
public override string Issue => "Setting BackButtonBehavior to not visible or not enabled does not work";
12+
13+
[Test]
14+
[Category(UITestCategories.Shell)]
15+
[Category(UITestCategories.Navigation)]
16+
public void BackButtonShouldNotBeVisible()
17+
{
18+
App.WaitForElement("NavigateToDetailButton");
19+
App.Click("NavigateToDetailButton");
20+
App.WaitForElement("HelloLabel");
21+
App.WaitForNoElement("BackButton");
22+
}
23+
}

0 commit comments

Comments
 (0)