From wpf-dev-pack
Explains WPF rendering pipeline including Measure/Arrange/Render passes, invalidation methods, and hardware acceleration tiers. Use for debugging layouts, optimizing performance, or diagnosing software rendering.
How this skill is triggered — by the user, by Claude, or both
Slash command
/wpf-dev-pack:rendering-wpf-architectureopusThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
```
User Input → Property Change → InvalidateXxx()
↓
┌───────────────┐
│ Measure Pass │ → Determines DesiredSize
├───────────────┤
│ Arrange Pass │ → Determines ActualSize/Position
├───────────────┤
│ Render Pass │ → OnRender() / DrawingContext
└───────────────┘
↓
Composition Tree → MILCore → DirectX → GPU
| Method | Triggers | Use When |
|---|---|---|
InvalidateMeasure() | Measure + Arrange + Render | Size might change |
InvalidateArrange() | Arrange + Render | Position might change |
InvalidateVisual() | Render only | Visual appearance change |
public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register("Radius", typeof(double), typeof(MyControl),
new FrameworkPropertyMetadata(10.0,
FrameworkPropertyMetadataOptions.AffectsRender |
FrameworkPropertyMetadataOptions.AffectsMeasure));
| Flag | Effect |
|---|---|
AffectsMeasure | Triggers Measure pass |
AffectsArrange | Triggers Arrange pass |
AffectsRender | Triggers Render pass |
AffectsParentMeasure | Parent re-measures |
AffectsParentArrange | Parent re-arranges |
protected override Size MeasureOverride(Size availableSize)
{
// Calculate desired size based on content
double width = Math.Min(200, availableSize.Width);
double height = Math.Min(100, availableSize.Height);
return new Size(width, height);
}
protected override Size ArrangeOverride(Size finalSize)
{
// Position children within finalSize
foreach (UIElement child in Children)
{
child.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
}
return finalSize;
}
protected override void OnRender(DrawingContext dc)
{
dc.DrawRectangle(Background, null, new Rect(RenderSize));
}
| Tier | GPU Memory | Features |
|---|---|---|
| 0 | < 30MB | Software rendering |
| 1 | 30-120MB | Partial hardware (no PS 2.0) |
| 2 | ≥ 120MB | Full hardware acceleration |
int tier = RenderCapability.Tier >> 16;
// 0 = Software, 1 = Partial, 2 = Full GPU
WPF falls back to software rendering when:
AllowsTransparency="True" on WindowBitmapEffect used// For images that will be scaled
RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.LowQuality);
// For pixel-perfect lines
RenderOptions.SetEdgeMode(element, EdgeMode.Aliased);
// For tiled brushes
RenderOptions.SetCachingHint(brush, CachingHint.Cache);
RenderOptions.SetCacheInvalidationThresholdMinimum(brush, 0.5);
RenderOptions.SetCacheInvalidationThresholdMaximum(brush, 2.0);
// Bad: Multiple layout passes
for (int i = 0; i < 100; i++)
{
items[i].Width = newWidths[i]; // Each triggers layout
}
// Good: Single layout pass
using (Dispatcher.DisableProcessing())
{
for (int i = 0; i < 100; i++)
{
items[i].Width = newWidths[i];
}
} // Layout happens once here
| Problem | Cause | Solution |
|---|---|---|
| Slow scrolling | Deep Visual Tree | Virtualization |
| Layout thrashing | Frequent InvalidateMeasure | Batch updates |
| Slow startup | Complex Grid | Simplify layout |
| Memory growth | BitmapEffect | Use Effect class |
public void ConfigureForTier()
{
int tier = RenderCapability.Tier >> 16;
if (tier < 2)
{
// Disable expensive effects
DisableDropShadows();
DisableAnimations();
UseSimplifiedVisuals();
}
}
npx claudepluginhub christian289/dotnet-with-claudecode --plugin wpf-dev-packOptimizes WPF memory usage via Freezable patterns, fixes common leaks from events, CompositionTarget.Rendering, timers, bindings, and images, with diagnostic checklists. Use for memory growth or leak debugging.
Designs WinUI 3 UIs and reviews XAML for correctness, covering layout planning, control selection, Fluent Design, theming (Light/Dark/HighContrast), typography, spacing, brushes, accessibility, and data binding.
Building WPF on .NET 8+. Host builder, MVVM Toolkit, Fluent theme, performance, modern C# patterns.