Put the vector shape in StatusDot.html and bind its fill color.
dotnet add package RecursiveAI.OneUIRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
<svg viewBox="0 0 18 18" aria-hidden="true"> <circle cx="9" cy="9" r="8" fill="{Fill}" /> </svg>
The example is the full program below: unzip it and dotnet run.
{Fill} sets the circle’s fill from C#. OneUI creates the shape in the SVG namespace; you don’t need to add xmlns to the template.
The full program
Put StatusDot.html and its matching partial class file, StatusDot.cs, in the same folder. OneUI generates the implementation of Fill and the code that updates the circle. The console sample uses ReferenceDocument, an in-memory host that doesn’t open a window. For pixels on screen, mount the component in a OneApp window or browser host.
StatusDot.cs:
using OneUI.Components; public partial class StatusDot { [State] public partial string Fill { get; set; } public StatusDot() => Fill = "gray"; }
Program.cs:
using OneUI.Components; using OneUI.Components.Reference; var doc = new ReferenceDocument(); var ui = new UiContext(doc); doc.Context = ui; var dot = new StatusDot(); ui.Mount(dot); var circle = doc.Require("circle"); Console.WriteLine($"SVG namespace: {circle.Namespace}"); Console.WriteLine($"Before: {circle.GetAttribute("fill")}"); dot.Fill = "green"; Console.WriteLine($"After: {circle.GetAttribute("fill")}");
dotnet run prints:
SVG namespace: http://www.w3.org/2000/svg Before: gray After: green
SVG names are case-sensitive: for example, viewbox instead of viewBox produces the build error OUI0011.
Variations
For an outlined dot, replace the <circle> with this one. The same state now controls the outline, not the interior. Read stroke instead of fill in the console app to see the change:
<circle cx="9" cy="9" r="8" fill="none" stroke="{Fill}" stroke-width="2" />
Related recipes
The short answer
Write <svg> directly in your OneUI template, put the shapes inside it and bind a supported attribute such as fill="{Fill}". OneUI recognizes the SVG subtree and creates namespaced nodes; changes to the C# state update the attribute on the existing shape. There’s no image file to reload when the color changes.
Do you need xmlns for inline SVG?
Not in a OneUI template. The <svg> tag tells the compiler to create SVG nodes. It accepts an explicit xmlns but doesn’t use it to choose the namespace. The equivalent HTML element and SVG element can have different rules, so the compiler checks this subtree against its SVG element and attribute list. Keep the casing of names like viewBox and linearGradient when you paste a design from an SVG file.
How do you change inline SVG color from C#?
Bind fill for the interior of a shape or stroke for the outline, as in the two examples above. Change the corresponding [State] property when the status changes. Set the presentation attributes on the shapes rather than relying on a selector inside the SVG: the OneUI docs note that page CSS rules don’t reach inside inline SVG in the native renderer. A shape using currentColor can follow the SVG root’s CSS color.
OneUI accepts paths, basic shapes, gradients and a documented set of other SVG elements. It rejects constructs such as SVG text, filters and animation, even if they work in a standalone SVG viewer. If the icon conveys a status, pair it with a visible HTML label rather than using the color alone; the sample dot is marked aria-hidden because it is decorative.