rendering-mewui-elements
Rendering Pipeline
MewUI uses a three-pass layout system:
Measure (calculate DesiredSize) → Arrange (set Bounds) → Render (draw via IGraphicsContext)
Key overrides in custom controls:
MeasureContent(Size availableSize)→ return desired sizeArrangeContent(Rect bounds)→ position childrenOnRender(IGraphicsContext context)→ draw visuals
IGraphicsContext Essentials
protected override void OnRender(IGraphicsContext context)
{
var bounds = new Rect(0, 0, Bounds.Width, Bounds.Height);
// State management (always Save/Restore)
context.Save();
context.Translate(10, 10);
context.SetClip(clipRect);
// ... drawing ...
context.Restore();
// Drawing primitives
context.FillRectangle(bounds, Colors.Blue);
context.DrawRectangle(bounds, Colors.Black, thickness: 1);
context.FillRoundedRectangle(bounds, radiusX: 4, radiusY: 4, Colors.White);
context.DrawLine(start, end, Colors.Gray, thickness: 1);
context.FillEllipse(bounds, Colors.Red);
// Text - note parameter order: text, bounds, font, color, alignments, wrapping
context.DrawText("Hello", bounds, font, Colors.Black,
TextAlignment.Center, TextAlignment.Center, TextWrapping.NoWrap);
// Images
context.DrawImage(image, destRect);
}
Text Measurement
protected override Size MeasureContent(Size availableSize)
{
var factory = GetGraphicsFactory();
using var ctx = factory.CreateMeasurementContext(GetDpi()); // uint dpi (96, 144, etc.)
return ctx.MeasureText(Text, GetFont(), availableSize.Width);
}
Graphics Backends
Application.DefaultGraphicsBackend = GraphicsBackend.Direct2D; // GPU (Windows)
Application.DefaultGraphicsBackend = GraphicsBackend.Gdi; // Software (Windows)
Application.DefaultGraphicsBackend = GraphicsBackend.OpenGL; // Cross-platform
Invalidation
InvalidateMeasure(); // Re-measure + re-arrange + re-render
InvalidateArrange(); // Re-arrange + re-render
InvalidateVisual(); // Re-render only
Detailed API: See graphics-api.md Pipeline details: See pipeline.md
More from christian289/dotnet-with-claudecode
converting-html-css-to-wpf-xaml
Converts HTML/CSS to WPF CustomControl XAML with correct patterns and common pitfall solutions. Use when transforming web designs to WPF, converting CSS animations to Storyboards, implementing CSS border-radius clipping, CSS pseudo-elements (::before/::after), or CSS transforms in XAML.
56publishing-wpf-apps
Guides WPF application publishing and installer options. Use when user mentions publish, deploy, release, packaging, or installer to help choose deployment method and installer technology.
14using-avalonia-collectionview
Provides CollectionView alternatives for AvaloniaUI using DataGridCollectionView and ReactiveUI. Use when filtering, sorting, or grouping collections in AvaloniaUI applications.
9designing-avalonia-customcontrol-architecture
Defines the basic solution structure for AvaloniaUI Desktop Applications using CustomControl. Use when creating new AvaloniaUI projects or designing stand-alone control styles with ControlTheme.
9using-xaml-property-element-syntax
Converts long inline XAML bindings to Property Element Syntax for better readability. Use when XAML binding expressions become too long or complex.
8managing-styles-resourcedictionary
Manages WPF Style definitions and ResourceDictionary patterns including BasedOn inheritance and resource merging. Use when building theme systems, organizing resources, or choosing between StaticResource and DynamicResource.
8