Skip to content

Conversation

Copy link

Copilot AI commented Nov 18, 2025

GitHub Issue (If applicable): Fixes issue described in problem statement

PR Type

  • Bugfix

What is the current behavior?

On iOS with Native renderer, when MainCommandStyle is set on a NavigationBar (typically via a global style), the style is not applied to the MainCommand AppBarButton. The back button fails to render despite no errors.

Root cause: NavigationBarPresenter.SetBindings() only applies the style if MainCommand already exists on the CommandBar at binding time. When styles are applied globally or MainCommand is set lazily via data binding, the style binding is never established.

What is the new behavior?

MainCommandStyle is applied regardless of when MainCommand is set. The fix applies the MainCommandStyle directly in NavigationBar.OnPropertyChanged when MainCommandProperty changes.

// Style now applies correctly whether set before or after MainCommand
var navBar = new NavigationBar 
{ 
    MainCommandStyle = myStyle  // Applied when MainCommand is set
};

The solution handles both scenarios:

  • If MainCommandStyle is set first, then MainCommand is set later → style is applied when MainCommand changes
  • If MainCommand is set first, then MainCommandStyle is set later → style is applied when MainCommandStyle changes

PR Checklist

Other information

Changes are minimal and surgical:

  • NavigationBar.cs: Added 6 lines in OnPropertyChanged method to apply MainCommandStyle when MainCommandProperty changes
  • NavigationBarTests.cs: Added test verifying style application

Co-authored-by: @kazo0

Internal Issue (If applicable): N/A

Original prompt

This section details on the original issue you should resolve

<issue_title>[iOS][NavigationBar] MainCommand (Back button) not appearing when icon is set from style</issue_title>
<issue_description>## Current behavior

MainCommand does not appear when setting the icon on a global style, no error is shown it just doesn't render. When removing it from the style, appears behaves as expected.

SideNote: This is using Native renderer

Expected behavior

Main Command should appear and navigte back when backstack is not empty even if the icon is set from style.

How to reproduce it (as minimally and precisely as possible)

  1. Create a new Uno Platform application with this features:
  2. Create an style for main command AppBarButton
  3. Set a global default style for NavigationBar control and set Style for MainCommand
  4. Run Application and navigate to second page
  5. back button doesn't appear (if icon is removed main command appears and works correctly)

Repro project:
NavBarTest.zip
Nuget Package:

Package Version(s):

Uno.Sdk 6.0.96
Uno.Toolkit.WinUI 7.0.2
Uno.Toolkit.Skia.WinUI 7.0.2

Installed Workloads:

Workload version: 9.0.203

Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------
android                    35.0.61/9.0.100        SDK 9.0.300        
ios                        18.4.9288/9.0.100      SDK 9.0.300        
maccatalyst                18.4.9288/9.0.100      SDK 9.0.300        
macos                      15.4.9288/9.0.100      SDK 9.0.300        
maui                       9.0.14/9.0.100         SDK 9.0.300        
tvos                       18.4.9288/9.0.100      SDK 9.0.300        
wasm-tools                 9.0.4/9.0.100          SDK 9.0.300    

Affected platform(s):

  • WebAssembly
  • Android
  • iOS
  • macOS (AppKit)
  • Mac Catalyst
  • Skia
    • WPF
    • GTK (Linux)
    • Linux Framebuffer
    • Tizen
  • Windows

IDE:

  • Visual Studio 2022
  • Visual Studio 2019
  • Visual Studio Code
  • Visual Studio for Mac
  • Rider Windows
  • Rider macOS

Relevant plugins:

Anything else we need to know?

Friction: for some reason now I can't run the samples.Mobile projects on MacOS Jetbrains Rider
</issue_description>

<agent_instructions>Seems that the issue is the MainCommandStyle is not being set onto the AppBarButton unless a MainCommand is explicitly added to the NavigationBar:

var MainCommand = CommandBarExtensions.GetMainCommand(_commandBar);
if (MainCommand != null)
{
setBinding(MainCommand, navigationBar, AppBarButton.StyleProperty, nameof(navigationBar.MainCommandStyle));
}

We should be hooking onto the MainCommand property change and set the style if the MainCommand instance has changed</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@kazo0 Seems that the issue is the MainCommandStyle is not being set onto the AppBarButton unless a MainCommand is explicitly added to the NavigationBar: https://github.com/unoplatform/uno.toolkit.ui/blob/c90bc57d726969f76d5a2875f260510ef592abb9/src/Uno.Toolkit.UI/Controls/NavigationBar/NavigationBarPresenter.cs#L118-L122

We should be hooking onto the MainCommand property change and set the style if the MainCommand instance has changed</comment_new>

Custom agent used: toolkit-bug-fix-bot
Identifies critical bugs in your project and implements targeted fixes with working code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Fix MainCommand not appearing on NavigationBar style fix(iOS): MainCommand style not applied when set via NavigationBar style Nov 18, 2025
Copilot AI requested a review from kazo0 November 18, 2025 22:51
Copilot finished work on behalf of kazo0 November 18, 2025 22:51
@kazo0
Copy link
Contributor

kazo0 commented Nov 19, 2025

@copilot We should be making this change in the NavigationBar.cs file in the OnPropertyChanged method here:

private void OnPropertyChanged(DependencyPropertyChangedEventArgs args)

…nstead of NavigationBarPresenter

Co-authored-by: kazo0 <[email protected]>
Copy link
Author

Copilot AI commented Nov 19, 2025

@copilot We should be making this change in the NavigationBar.cs file in the OnPropertyChanged method here: https://github.com/unoplatform/uno.toolkit.ui/blob/c90bc57d726969f76d5a2875f260510ef592abb9/...

Done! Moved the fix to NavigationBar.cs OnPropertyChanged method as suggested. The solution is now simpler - when MainCommandProperty changes, we apply the MainCommandStyle if both are set. This handles the case where MainCommand is set after MainCommandStyle.

Changes in commit 71e17bd:

  • Added 6 lines to NavigationBar.cs to apply style when MainCommand changes
  • Reverted all NavigationBarPresenter.cs changes from the previous approach

Copilot finished work on behalf of kazo0 November 19, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS][NavigationBar] MainCommand (Back button) not appearing when icon is set from style

3 participants