Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ internal bool SendPop()
if (tracker.Value.ViewController == TopViewController)
{
var behavior = Shell.GetEffectiveBackButtonBehavior(tracker.Value.Page);
var enabled = behavior.GetPropertyIfSet(BackButtonBehavior.IsEnabledProperty, true);
var command = behavior.GetPropertyIfSet<ICommand>(BackButtonBehavior.CommandProperty, null);
var commandParameter = behavior.GetPropertyIfSet<object>(BackButtonBehavior.CommandParameterProperty, null);

if (!enabled)
{
return false;
}

if (command != null)
{
if (command.CanExecute(commandParameter))
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Shell/BackButtonBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public string TextOverride
set { SetValue(TextOverrideProperty, value); }
}

bool IsEnabledCore { set => SetValue(IsEnabledProperty, value); }
bool IsEnabledCore { set => SetValue(IsEnabledProperty, value && IsEnabled); }

static void OnCommandChanged(BindableObject bindable, object oldValue, object newValue)
{
Expand Down
45 changes: 45 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28722.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace Maui.Controls.Sample.Issues;
[Issue(IssueTracker.Github, 28722, "IsEnabled does not work in BackButtonBehavior", PlatformAffected.iOS)]
public class Issue28722 : Shell
{
public Issue28722()
{
Routing.RegisterRoute(nameof(Issue28722Page1), typeof(Issue28722Page1));
Items.Add(new ContentPage());
}

protected override void OnAppearing()
{
base.OnAppearing();
Current.GoToAsync(nameof(Issue28722Page1));

}
}

public class Issue28722Page1 : ContentPage
{
public Issue28722Page1()
{
var label = new Label()
{
Text = "Welcome to Page 1",
AutomationId = "HelloLabel",
IsVisible = false
};

var backButtonBehavior = new BackButtonBehavior()
{
IsEnabled = true,
TextOverride = "Click",
};

backButtonBehavior.Command = new Command(() =>
{
label.IsVisible = !label.IsVisible;
backButtonBehavior.IsEnabled = false;
});

Shell.SetBackButtonBehavior(this, backButtonBehavior);
Content = label;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue28722 : _IssuesUITest
{
public Issue28722(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "IsEnabled does not work in BackButtonBehavior";

[Test]
[Category(UITestCategories.Shell)]
public void IsEnabledShouldWorkInBackButtonBehavior()
{
App.WaitForElement("Click");
App.Click("Click");
App.WaitForElement("HelloLabel");
App.Click("Click");
App.WaitForElement("HelloLabel");
}
}
}
Loading