You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
XAML: Show color swatches for named colors (e.g. Red, CornflowerBlue) #209
The XAML language server currently shows color swatches only for hex color literals (e.g. #FF0000). Named WinUI colors like Red, CornflowerBlue, DarkSlateGray should also display inline color swatches in the editor.
Current state
XamlColor.cs parses hex literals and returns ColorInformation to the LSP client
XamlTypeSystem.GetNamedColors() already discovers named color constants via Roslyn (e.g. Microsoft.UI.Colors.Red)
However, Roslyn cannot evaluate property getters at design time, so the actual RGBA values for named colors are not available from the type system alone
Proposed approach
Import a build-time lookup table of named color → RGBA mappings from the WinAppSDK source (or a generated resource). This table would be used by XamlColor to resolve named colors to their swatch values without requiring runtime evaluation.
Worth doing, and no hard-coded hex table is needed. The proposed approach here (a build-time import of named color to RGBA from the WinAppSDK source) can be dropped.
The premise in this issue is correct as far as it goes: GetNamedColors() returns only IPropertySymbol.Name values, and Roslyn genuinely cannot evaluate Microsoft.UI.Colors.Red, because those getters are implemented natively in the WinRT projection. But the conclusion that we must therefore import a value table does not follow. The names WinUI exposes are the W3C/X11 set, and .NET already ships that exact table in System.Drawing.Primitives.
Verified empirically rather than assumed, on net10.0:
Assembly: System.Drawing.Primitives
Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\10.0.11\System.Drawing.Primitives.dll
names probed: 141
not resolved: 0
Red expected FFFF0000 actual FFFF0000 OK
CornflowerBlue expected FF6495ED actual FF6495ED OK
DarkSlateGray expected FF2F4F4F actual FF2F4F4F OK
Transparent expected 00FFFFFF actual 00FFFFFF OK
bogus name resolves: False
All 141 names (the 140 X11 colors plus Transparent) resolve, ARGB matches W3C exactly, and Transparent correctly comes back as 00FFFFFF rather than 00000000. Three properties that matter for us:
It lives in the shared framework, not a NuGet package, so there is no new dependency and nothing extra to carry in the self-contained publish.
Color.FromName is a pure managed lookup with no native System.Drawing dependency, so it is safe on any host.
It is data we do not own or maintain, which is the whole point of not hard-coding.
One design constraint worth writing down.Color.FromName also resolves .NET system colors such as Control, Desktop, and ActiveBorder, which Microsoft.UI.Colors does not have. So FromName must not be the gate on what counts as a valid color name. GetNamedColors() stays authoritative for which names exist, since it reads the real SDK metadata for the project's WinAppSDK version, and System.Drawing is used only to resolve a name we have already accepted into RGBA. That keeps the accepted set correct even if a future SDK adds or removes a name.
Second question worth deciding before implementing: what ColorPresentation should offer when a user opens the picker on a named color. Right now Present only emits hex, so picking a new color over Red would rewrite it as #FFFF00FF and silently lose the symbolic name. That matches how CSS tooling behaves and is probably acceptable, but offering the nearest named color alongside the hex would be friendlier. Worth an explicit call rather than falling out of the implementation by accident.
Estimated cost is small: a lookup gated on GetNamedColors(), a branch in XamlColor.Collect next to TryParseHex, and tests. No new dependency, no generated file, no table to keep in sync with the SDK.
Activity
chiaramooney commentedon Sep 8, 2026
Worth doing, and no hard-coded hex table is needed. The proposed approach here (a build-time import of named color to RGBA from the WinAppSDK source) can be dropped.
The premise in this issue is correct as far as it goes:
GetNamedColors()returns onlyIPropertySymbol.Namevalues, and Roslyn genuinely cannot evaluateMicrosoft.UI.Colors.Red, because those getters are implemented natively in the WinRT projection. But the conclusion that we must therefore import a value table does not follow. The names WinUI exposes are the W3C/X11 set, and .NET already ships that exact table inSystem.Drawing.Primitives.Verified empirically rather than assumed, on net10.0:
All 141 names (the 140 X11 colors plus
Transparent) resolve, ARGB matches W3C exactly, andTransparentcorrectly comes back as00FFFFFFrather than00000000. Three properties that matter for us:Color.FromNameis a pure managed lookup with no nativeSystem.Drawingdependency, so it is safe on any host.One design constraint worth writing down.
Color.FromNamealso resolves .NET system colors such asControl,Desktop, andActiveBorder, whichMicrosoft.UI.Colorsdoes not have. SoFromNamemust not be the gate on what counts as a valid color name.GetNamedColors()stays authoritative for which names exist, since it reads the real SDK metadata for the project's WinAppSDK version, andSystem.Drawingis used only to resolve a name we have already accepted into RGBA. That keeps the accepted set correct even if a future SDK adds or removes a name.Second question worth deciding before implementing: what
ColorPresentationshould offer when a user opens the picker on a named color. Right nowPresentonly emits hex, so picking a new color overRedwould rewrite it as#FFFF00FFand silently lose the symbolic name. That matches how CSS tooling behaves and is probably acceptable, but offering the nearest named color alongside the hex would be friendlier. Worth an explicit call rather than falling out of the implementation by accident.Estimated cost is small: a lookup gated on
GetNamedColors(), a branch inXamlColor.Collectnext toTryParseHex, and tests. No new dependency, no generated file, no table to keep in sync with the SDK.Show color swatches for WinUI named colors