Back to list
christian289

rendering-wpf-architecture

by christian289

ClaudeCode와 함께하는 .NET 개발 튜토리얼

1🍴 0📅 Jan 25, 2026

SKILL.md


name: rendering-wpf-architecture description: Explains WPF rendering pipeline (Measure/Arrange/Render passes) and hardware acceleration tiers. Use when debugging layout issues, optimizing render performance, or understanding why software rendering occurs.

WPF Rendering Architecture

Rendering Pipeline Overview

User Input → Property Change → InvalidateXxx()
                ↓
        ┌───────────────┐
        │ Measure Pass  │ → Determines DesiredSize
        ├───────────────┤
        │ Arrange Pass  │ → Determines ActualSize/Position
        ├───────────────┤
        │ Render Pass   │ → OnRender() / DrawingContext
        └───────────────┘
                ↓
    Composition Tree → MILCore → DirectX → GPU

1. Layout Passes

Invalidation Methods

MethodTriggersUse When
InvalidateMeasure()Measure + Arrange + RenderSize might change
InvalidateArrange()Arrange + RenderPosition might change
InvalidateVisual()Render onlyVisual appearance change

FrameworkPropertyMetadata Flags

public static readonly DependencyProperty RadiusProperty =
    DependencyProperty.Register("Radius", typeof(double), typeof(MyControl),
        new FrameworkPropertyMetadata(10.0,
            FrameworkPropertyMetadataOptions.AffectsRender |
            FrameworkPropertyMetadataOptions.AffectsMeasure));
FlagEffect
AffectsMeasureTriggers Measure pass
AffectsArrangeTriggers Arrange pass
AffectsRenderTriggers Render pass
AffectsParentMeasureParent re-measures
AffectsParentArrangeParent re-arranges

Custom Control Layout

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));
}

2. Hardware Acceleration

Rendering Tiers

TierGPU MemoryFeatures
0< 30MBSoftware rendering
130-120MBPartial hardware (no PS 2.0)
2≥ 120MBFull hardware acceleration
int tier = RenderCapability.Tier >> 16;
// 0 = Software, 1 = Partial, 2 = Full GPU

Software Fallback Conditions

WPF falls back to software rendering when:

  • GPU memory insufficient
  • Texture > 8192px
  • Remote Desktop (RDP) session
  • AllowsTransparency="True" on Window
  • Legacy BitmapEffect used

RenderOptions Optimization

// 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);

3. Performance Optimization

Batch Updates Pattern

// 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

Common Performance Issues

ProblemCauseSolution
Slow scrollingDeep Visual TreeVirtualization
Layout thrashingFrequent InvalidateMeasureBatch updates
Slow startupComplex GridSimplify layout
Memory growthBitmapEffectUse Effect class

4. Tier-Adaptive Rendering

public void ConfigureForTier()
{
    int tier = RenderCapability.Tier >> 16;

    if (tier < 2)
    {
        // Disable expensive effects
        DisableDropShadows();
        DisableAnimations();
        UseSimplifiedVisuals();
    }
}

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon