Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/8.0.1xx-sr9] NullReferenceException when setting BarBackgroundColor for a NavigationPage - fix #25251

Merged
merged 6 commits into from
Oct 14, 2024
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 @@ -33,7 +33,6 @@ public NavigationPageToolbar(Maui.IElement parent, Page rootPage) : base(parent)
_toolbarTracker.CollectionChanged += OnToolbarItemsChanged;
RootPage = rootPage;
_toolbarTracker.PageAppearing += OnPageAppearing;
_toolbarTracker.PagePropertyChanged += OnPagePropertyChanged;
_toolbarTracker.Target = RootPage;
}

Expand Down Expand Up @@ -71,6 +70,7 @@ void OnPageAppearing(object sender, EventArgs e)
if (sender is not ContentPage cp)
return;

_toolbarTracker.PagePropertyChanged -= OnPagePropertyChanged;
_currentPage = cp;
_currentNavigationPage = _currentPage.FindParentOfType<NavigationPage>();

Expand Down Expand Up @@ -112,6 +112,7 @@ void OnPageAppearing(object sender, EventArgs e)
_hasAppeared = true;

ApplyChanges(_currentNavigationPage);
_toolbarTracker.PagePropertyChanged += OnPagePropertyChanged;
}

// This is to catch scenarios where the user
Expand Down
40 changes: 40 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25114.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Maui.Controls.Sample.Issues;
using Microsoft.Maui.Controls;

[Issue(IssueTracker.Github, 25114, "NullReferenceException when setting BarBackgroundColor for a NavigationPage", PlatformAffected.All)]
public class Issue25114Flyout : FlyoutPage
{
public Issue25114Flyout()
{
var navPage = new NavigationPage(new Issue25114());
navPage.SetDynamicResource(NavigationPage.BarBackgroundColorProperty, "Primary");
Detail = navPage;
Flyout = new ContentPage
{
Title = "Flyout"
};
}
}

public class Issue25114 : ContentPage
{
public Issue25114()
{
Content = new Button()
{
AutomationId = "button",
HeightRequest = 100,
Text = "Change the Navigation Bar's Color",
Command = new Command(() =>
{
Application.Current.Resources["Primary"] = "#0000FF";
})
};
}

protected override void OnAppearing()
{
base.OnAppearing();
Application.Current.Resources["Primary"] = "#00FF00";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue25114 : _IssuesUITest
{
public Issue25114(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "NullReferenceException when setting BarBackgroundColor for a NavigationPage";

[Test]
[Category(UITestCategories.FlyoutPage)]
public void NoExceptionShouldBeThrownWhenChangingNavigationBarColor()
{
App.WaitForElement("button");
App.Tap("button");
}

}