Skip to content

Fixed Toolbar IconImageSource not updating with Binding Changes #27402

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

Merged
merged 6 commits into from
Feb 19, 2025

Conversation

NirmalKumarYuvaraj
Copy link
Contributor

Issue Details

The toolbar item's FontImageSource Glyph is not reflecting changes when the bound property is updated in the ViewModel. The icon remains static despite property changes in the binding source.

Root Cause

The MenuItem class lacks an implementation to listen for source changes in the IconImageSource property. When the Glyph property changes in the bound FontImageSource, the MenuItem is not notified of this change.As a result, the visual update is not triggered in the UI

Description of Change

Implementing a source changed event listener for IconImageSource in the ImageSource call back. When the ImageSource changes are detected, manually triggering PropertyChanged for IconImageSource.This propagates the change through the UI update mechanism, ensuring the toolbar icon reflects the new state.

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #8295

Output

Before After
Before.mov
After.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jan 28, 2025
@vishnumenon2684 vishnumenon2684 added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jan 28, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@NirmalKumarYuvaraj NirmalKumarYuvaraj marked this pull request as ready for review February 3, 2025 03:26
@NirmalKumarYuvaraj NirmalKumarYuvaraj requested a review from a team as a code owner February 3, 2025 03:26
@dotnet dotnet deleted a comment from azure-pipelines bot Feb 5, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mattleibow
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

newImageSource.SourceChanged += ((MenuItem)bindable).OnImageSourceSourceChanged;
}

void OnImageSourceSourceChanged(object sender, EventArgs e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't required. it's already done elsewhere (I'm quite sure)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StephaneDelcroix , Yes, the ImageElement.SourcePropertycontains the implementation of the sourceChanged event in its callback. However, replacing the existing Source property with ImageElement.SourceProperty results in an InvalidCastException at runtime. I referred to the Button.cs file for implementing ImageElement.SourceProperty in MenuItem.cs. The crash occurs because MenuItem is being converted to a VisualElement, whereas its base class is StylableElement, not VisualElement. In contrast, Button has VisualElement as its base class. Therefore, I proceeded with implementing the current code changes in this file alone.

@jfversluis jfversluis added this to the .NET 9 SR5 milestone Feb 19, 2025
@jfversluis jfversluis dismissed jsuarezruiz’s stale review February 19, 2025 11:03

Feedback addressed

@jfversluis jfversluis merged commit 35007f5 into dotnet:main Feb 19, 2025
126 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Can't Change ToolbarItem FontIconSource Glyph After Load
6 participants