Skip to content

Add standalone IconElement for the element tree#271

Merged
codemonkeychris merged 2 commits into
mainfrom
icon-element
May 19, 2026
Merged

Add standalone IconElement for the element tree#271
codemonkeychris merged 2 commits into
mainfrom
icon-element

Conversation

@sundaramramaswamy
Copy link
Copy Markdown
Collaborator

Summary

Adds a new IconElement(IconData Data) record that wraps the existing IconData hierarchy so icons can be placed as standalone children in any layout container.

Before: IconData records (SymbolIconData, FontIconData, etc.) could only be used as data slots on composite controls (NavigationViewItemData, MenuFlyoutItemData, etc.). There was no way to render a standalone icon in the element tree.

After:

Icon("Home")
Icon(FontIcon("\uE700", "Segoe Fluent Icons"))
Icon(BitmapIcon(new Uri("ms-appx:///icon.png")))

Changes

File Change
Element.cs New IconElement(IconData Data) : Element record
Dsl.cs Icon(IconData) and Icon(string) factory methods
Reconciler.Mount.cs MountIcon — delegates to existing ResolveIcon
Reconciler.Update.cs UpdateIcon — patches same-type, replaces on cross-type change
ElementExtensions.cs .Set(Action<IconElement>) fluent modifier
ElementRecordCoverageTests.cs 4 new unit tests

Testing

  • All 7237 unit tests pass (0 failures)
  • Full solution builds cleanly

Closes #257

Comment thread skills/reactor.api.txt
HyperlinkButton(Command command) → HyperlinkButtonElement
HyperlinkButton(string content, Uri navigateUri = null, Action onClick = null) → HyperlinkButtonElement
Icon(IconData data) → IconElement
Icon(string symbol) → IconElement
Copy link
Copy Markdown
Collaborator

@dotMorten dotMorten May 13, 2026

Choose a reason for hiding this comment

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

Do we need one that takes the Symbol enum? It'll be a lot easier to code again instead of a stringified version of it? https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.symbolicon.symbol?view=windows-app-sdk-1.8#microsoft-ui-xaml-controls-symbolicon-symbol

It would then generate the SymbolIcon IconElement

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah, i think the enum version is better.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good call - added an Icon(Symbol) overload in f18aed9 so you get full IntelliSense on the enum. The string overload is kept for raw glyph strings not in the enum.

Comment thread skills/reactor.api.txt
HyperlinkButton(Command command) → HyperlinkButtonElement
HyperlinkButton(string content, Uri navigateUri = null, Action onClick = null) → HyperlinkButtonElement
Icon(IconData data) → IconElement
Icon(string symbol) → IconElement
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah, i think the enum version is better.

@sundaramramaswamy
Copy link
Copy Markdown
Collaborator Author

@codemonkeychris All feedback has been addressed — added the Icon(Symbol) enum overload in f18aed9. Could you re-review when you get a chance?

sundaramramaswamy and others added 2 commits May 19, 2026 20:48
Wrap the existing IconData hierarchy (SymbolIconData,
FontIconData, BitmapIconData, PathIconData, ImageIconData)
in a new IconElement record that can be placed as a child
of any layout container.

- Element record: IconElement(IconData Data)
- Factory methods: Icon(IconData), Icon(string)
- Reconciler mount/update handlers
- Fluent .Set() extension
- Unit tests for record, factories, and with-expressions

Closes #257

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds an overload that takes the WinUI Symbol enum
directly for better discoverability and IntelliSense.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codemonkeychris codemonkeychris merged commit 937f6ca into main May 19, 2026
9 checks passed
@codemonkeychris codemonkeychris deleted the icon-element branch May 19, 2026 16:25
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.

[Feature] There's no mapping for Microsoft.UI.Xaml.Controls.IconSourceElement

3 participants