Skip to content
Draft
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
27 changes: 26 additions & 1 deletion src/Uno.Toolkit.RuntimeTests/Tests/NavigationBarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,32 @@ private static void AssertNavigationBar(Frame frame)
#endif
#endif

private sealed partial class FirstPage : Page
[TestMethod]
public async Task MainCommandStyle_Applied_From_NavigationBar_Style()
{
// Create a style for MainCommand with a specific icon
var mainCommandStyle = new Style(typeof(AppBarButton));
mainCommandStyle.Setters.Add(new Setter(AppBarButton.IconProperty, new SymbolIcon(Symbol.Back)));

// Create NavigationBar with MainCommandStyle set
var navigationBar = new NavigationBar
{
Content = "Title",
MainCommandMode = MainCommandMode.Action,
MainCommandStyle = mainCommandStyle
};

var content = new Grid { Children = { navigationBar } };
await UnitTestUIContentHelperEx.SetContentAndWait(content);
await UnitTestsUIContentHelper.WaitForIdle();

// Verify that MainCommand has the style applied
Assert.IsNotNull(navigationBar.MainCommand, "MainCommand should not be null");
Assert.IsNotNull(navigationBar.MainCommand.Style, "MainCommand.Style should not be null");
Assert.AreEqual(mainCommandStyle, navigationBar.MainCommand.Style, "MainCommand should have the MainCommandStyle applied");
}

private sealed partial class FirstPage : Page
{
public FirstPage()
{
Expand Down
6 changes: 6 additions & 0 deletions src/Uno.Toolkit.UI/Controls/NavigationBar/NavigationBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ private void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
if (args.Property == MainCommandProperty)
{
UpdateMainCommandVisibility();

// Apply MainCommandStyle to the new MainCommand instance
if (MainCommand is { } mainCommand && MainCommandStyle is { } mainCommandStyle)
{
mainCommand.Style = mainCommandStyle;
}
}
else if (args.Property == MainCommandModeProperty)
{
Expand Down
Loading