How does one disable hardware acceleration in wpf?

Stefan picture Stefan · Jan 30, 2010 · Viewed 18k times · Source

What is the procedure for disabling hardware acceleration in WPF? What is it exactly? Is it a Windows setting, a Visual Studio setting, or something you alter in the code of your WPF project? Will it affect only the program you're running or will it be system-wide?

Answer

Konstantin Spirin picture Konstantin Spirin · Mar 21, 2012

You can disable it on a Window level starting from .Net 3.5 SP1.

public partial class MyWindow : Window
{
    public MyWindow()
        : base()
    {
        InitializeComponent();
    }

    protected override void OnSourceInitialized(EventArgs e)
    {
        var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

        if (hwndSource != null)
            hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

        base.OnSourceInitialized(e);
    }
}

or you can subscribe to SourceInitialized event of the window and do the same.

Alternatively you can set it on Process level:

RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

The precedence order for software rendering is:

  1. DisableHWAcceleration registry key
  2. ProcessRenderMode
  3. RenderMode (per-target)