jeudi, 30 janvier 2014 12:04

Troubleshooting graphic issues in WPF applications

Share this post

Graphic issues in WPF applications can include any of the following symptoms:

·         A WPF window that fails to refresh.
·         A WPF window that contains distorted and corrupted visuals.
·         On Windows Vista, the screen flickers.
·         On Windows XP, a blue screen crash sometimes occurs.
·         The occurrence of a Timeout Detection and Recovery (TDR).

As reported (see here), depending on the machine configuration and the application, software-based rendering is sometimes faster than hardware.

A new API is now available to allow developers to force software rendering in his/her application (per window) instead of using the GPU.

Solution :

In the main window, set the event :

Loaded="OnLoaded"

In the code behind :

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    if (ForceSoftware)
    {
        HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
        HwndTarget hwndTarget = hwndSource.CompositionTarget;

        // this is the new WPF API to force render mode.
        hwndTarget.RenderMode = RenderMode.SoftwareOnly;
    }
}


Source information :

http://blogs.msdn.com/jgoldb/archive/2007/10/10/performance-improvements-in-wpf-in-net-3-5-3-0-sp1.aspx

Lu 27089 fois Dernière modification le jeudi, 30 janvier 2014 12:04