Skip to content
Shiny PlatformShiny Platform
Controls 3.0MAUI & Blazor NET11 Support

ShinyImage | Blazor

The Blazor component mirrors the MAUI control’s states — placeholder, ring, image, error artwork — but the machinery underneath is deliberately different.

The browser already has one: an HTTP cache on disk that revalidates with ETag / Last-Modified, shared across tabs and persisted between sessions. Reimplementing that in C# would be slower, would not be shared, and would fight the one the browser is going to use anyway.

So CacheEnabled, CacheDuration and IImageService have no Blazor counterparts. Set cache headers on the server.

What the browser’s cache doesn’t do is merge requests. A dozen images asking for an uncached URL at once would each make their own fetch and hold their own copy of the bytes. ShinyImage shares them:

  • Every image showing the same URL rides one fetch and one blob. A late arrival joins the fetch in flight and gets its current progress straight away, or, if it has finished, gets the blob immediately with no request.
  • The blob is reference-counted and released when the last image showing it goes away.
  • One image leaving the screen stops only its own wait. The fetch is cancelled only when nobody is waiting on it any more.
  • A failed load isn’t remembered, so the next image to ask tries again.
  • With an IImageDownloader registered, the same rules apply to the C# download: one call per URL per scope, which on Blazor Server means per user, so two users never share an authenticated image. The bytes cross into the browser once.

ReloadAsync() adds a cache-busting parameter, so a reload always fetches on its own. It reads the time from a TimeProvider registered in DI, or TimeProvider.System if none is.

Remote images are streamed through fetch and a ReadableStream reader, so the ring can show a genuine percentage. No <img> element can report this — the DOM has no progress event for images. That is the whole reason the component does anything more than emit an <img> tag.

The mode selection is the same as on MAUI: Percent is null when the response carried no Content-Length, and the ring spins instead of counting.

Nothing to configure. The browser renders SVG natively through <img>, including the filters, masks, patterns and animation that MAUI’s vector renderer does not draw. SvgTintColor has no Blazor counterpart — use CSS on the wrapper, or an inline <svg> if you need to restyle its internals.

Register a downloader so the bytes come through C# instead of the browser:

builder.Services.AddShinyImages(); // routes through the registered HttpClient
builder.Services.AddShinyImages<AuthenticatedDownloader>(); // or your own IImageDownloader

The Blazor IImageDownloader returns ImageDownloadResult(byte[] Bytes, string? ContentType) — a different shape from the MAUI one, because the bytes end up in a blob URL rather than in a file.

The wrapper takes CssClass, and ObjectFit maps to CSS object-fit (contain by default; cover is the other one most pages want). The ring colours are CSS colour strings rather than Color objects, and default to theme custom properties:

<ShinyImage Uri="@PhotoUrl"
ObjectFit="cover"
CssClass="rounded shadow"
RingColor="var(--shiny-color-primary)" />