Giovedì, 30 Gennaio 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 :


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 :

Letto 8318 volte Ultima modifica il Giovedì, 30 Gennaio 2014 12:04