Skip to content
OpenAgentSkill
Browsing is open · Catalog captured 2026-11-21 · Automatic updates and account services are paused.
Video & audio

avalonia-controls-media

Use when working with Avalonia media controls: Image, DrawingImage (incl. Viewbox 12.0+), PathIcon, MediaPlayerControl (LibVLCSharp), or NativeWebView/NativeWebDialog (Avalonia.Controls.WebView, open source in 12.0+, commercial in 11.x). Covers asset loading URIs, stretch modes, vector icons, video playback setup, and web content embedding.

linuxdevel · Static checks on file

Installation

Read the source and dependencies before running a command. Copying does not install or execute anything.

npx skills add linuxdevel/Avalonia-skills --skill avalonia-controls-media

About this skill


name: avalonia-controls-media description: Use when working with Avalonia media controls: Image, DrawingImage (incl. Viewbox 12.0+), PathIcon, MediaPlayerControl (LibVLCSharp), or NativeWebView/NativeWebDialog (Avalonia.Controls.WebView, open source in 12.0+, commercial in 11.x). Covers asset loading URIs, stretch modes, vector icons, video playback setup, and web content embedding.

Avalonia Media Controls

Overview

Media controls display images, vector graphics, and embedded web or video content. Image sources use avares:// URIs for app assets. Vector content (PathIcon, DrawingImage) scales without pixelation.


Image

Displays raster (PNG, JPEG, BMP, WebP) or vector images.

PropertyTypeNotes
SourceIImageBitmap, DrawingImage, bound IImage
StretchStretchNone, Fill, Uniform (default), UniformToFill
Width / HeightdoubleExplicit size; required if parent gives infinite space
RenderOptions.BitmapInterpolationModeBitmapInterpolationModeDefault, LowQuality, MediumQuality, HighQuality, None

Stretch modes:

ValueBehavior
NoneOriginal pixel size
FillStretches to fill, distorts aspect ratio
UniformLetterboxed to fit, preserves aspect ratio
UniformToFillFills area, may clip, preserves aspect ratio

Loading from app assets (AXAML):

<!-- Bundled asset — requires Build Action: AvaloniaResource -->
<Image Source="avares://MyApp/Assets/logo.png" Width="120" Height="40" Stretch="Uniform"/>

<!-- Relative path from project root (works at design time, runtime needs avares://) -->
<Image Source="/Assets/banner.jpg" Stretch="UniformToFill"/>

Loading in code:

using Avalonia.Platform;
using Avalonia.Media.Imaging;

// From app assets
var uri = new Uri("avares://MyApp/Assets/logo.png");
var bitmap = new Bitmap(AssetLoader.Open(uri));
myImage.Source = bitmap;

// From file system
var bitmap = new Bitmap("/home/user/photo.png");
myImage.Source = bitmap;

// From stream
using var stream = File.OpenRead(path);
var bitmap = new Bitmap(stream);

Binding to ViewModel:

// In ViewModel
private Bitmap? _photo;
public Bitmap? Photo
{
    get => _photo;
    set => SetProperty(ref _photo, value);
}

// Load async
public async Task LoadPhotoAsync(string path)
{
    await using var stream = File.OpenRead(path);
    Photo = await Task.Run(() => new Bitmap(stream));
}
<Image Source="{Binding Photo}" Width="200" Height="200" Stretch="UniformToFill"/>

Dispose Bitmaps when no longer needed to release native memory:

_photo?.Dispose();

DrawingImage

Vector image source built from geometry. Use for scalable icons embedded as image sources.

ClassUse
DrawingGroupCombines multiple drawings
GeometryDrawingFills/strokes a geometry path
ImageDrawingEmbeds a bitmap in a drawing
<Image Width="64" Height="64">
    <Image.Source>
        <DrawingImage>
            <DrawingImage.Drawing>
                <DrawingGroup>
                    <!-- Background circle -->
                    <GeometryDrawing Brush="#6200EE"
                                     Geometry="M 32,32 m -32,0 a 32,32 0 1,0 64,0 a 32,32 0 1,0 -64,0"/>
                    <!-- Foreground path -->
                    <GeometryDrawing Brush="White"
                                     Geometry="M 20,20 L 44,32 L 20,44 Z"/>
                </DrawingGroup>
            </DrawingImage.Drawing>
        </DrawingImage>
    </Image.Source>
</Image>

DrawingImage.Viewbox (12.0+) — Rect? in DIPs: which region of the Drawing to render. Crops the drawing or adds empty space around it. null (default) = the drawing's own bounds. Not in 11.x.

<DrawingImage Viewbox="0,0,64,64" Drawing="{StaticResource IconDrawing}"/>

Prefer PathIcon for simple icons. Use DrawingImage when you need composite layered vector drawings or need to embed as Image.Source.


PathIcon

SVG-path-based scalable icon. Preferred for UI icons. Color controlled by Foreground.

PropertyTypeNotes
DataGeometrySVG path string
ForegroundIBrushIcon color (inherits from parent)
Width / HeightdoubleDisplay size
<!-- Basic icon -->
<PathIcon Data="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"
          Width="24" Height="24" Foreground="{DynamicResource TextFillColorPrimaryBrush}"/>

<!-- Icon button -->
<Button>
    <PathIcon Data="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12z" Width="20" Height="20"/>
</Button>

<!-- Colored icon -->
<PathIcon Data="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 14.5v-9l6 4.5-6 4.5z"
          Width="32" Height="32" Foreground="#4CAF50"/>

<!-- Inside a style/template, inheriting parent foreground -->
<PathIcon Data="..." Width="16" Height="16"/>

Dynamic path from ViewModel:

<PathIcon Data="{Binding IconPathData}" Width="24" Height="24"/>
// In ViewModel
public string IconPathData => IsPlaying
    ? "M6 19h4V5H6v14zm8-14v14h4V5h-4z"   // pause icon
    : "M8 5v14l11-7z";                       // play icon

MediaPlayerControl (LibVLCSharp)

Avalonia does not include built-in video playback. Use LibVLCSharp.Avalonia.

NuGet packages:

LibVLCSharp
LibVLCSharp.Avalonia
VideoLAN.LibVLC.Windows  (or .Mac / .Linux)

Namespace: xmlns:vlc="using:LibVLCSharp.Avalonia"

<vlc:VideoView x:Name="VideoView" MediaPlayer="{Binding MediaPlayer}">
    <!-- Overlay controls rendered on top of video -->
    <Grid VerticalAlignment="Bottom" Background="#80000000">
        <StackPanel Orientation="Horizontal" Margin="8">
            <Button Content="⏮" Command="{Binding StopCommand}"/>
            <Button Content="{Binding PlayPauseLabel}" Command="{Binding PlayPauseComma
Read the complete source ↗