Skip to main content
A newer version of this page is available. .
All docs
V21.2

Preload Theme Resources

  • 2 minutes to read

Controls use theme resources (default styles, templates, keys) to change their appearance when you apply a DevExpress WPF Theme to the application.

A WPF application loads a control’s theme resources only when the control is about to be displayed. As a result, windows that rely on DevExpress WPF themes can take longer to appear.

This prolonged display time can be crucial when the first window of your application is lightweight (for example, a login form), and the main application window is heavy (it contains a large control or many controls). In this case, the first window appears quickly, but the second one can take a noticeable amount of time to load theme resources.

The PreloadThemeResourceAsync method allows you to speed up the display time of subsequent windows. This method preloads theme resources for the control assemblies that are referenced on these windows. You can use the PreloadThemeResourceAsync method both synchronously and asynchronously.

Refer to the following methods’ remarks for more information: PreloadThemeResourceAsync / PreloadThemeResource.

Asynchronous Theme Resource Preload

How to Use

Asynchronous theme preload works best when the application’s start window is lightweight, like a login form. In this case, you can use the PreloadThemeResourceAsync method to preload theme resources of the second window asynchronously while a user inputs login credentials.

Example

The following code sample creates static constructors and preloads the Office2019Colorful theme resources asynchronously at the application startup.

using System.Windows;
using System.Threading;
using DevExpress.Xpf.Core;

public partial class App : Application {
    protected async override void OnStartup(StartupEventArgs e) {
        base.OnStartup(e);
        await ThemeManager.PreloadThemeResourceAsync("Office2019Colorful");
    }
}

Issues

Asynchronous theme resource preload may slow down resource loading from the UI thread. Refer to the following section to avoid this shortcoming: Use Asynchronous Theme Preload on Dispatcher.

Synchronous Theme Resource Preload

When to Use

This technique works best when you display the Splashscreen Manager at the application startup. In this case, the method loads a control’s theme resources while a splashscreen is displayed.

Performance

Theme preload slows down application startup but speeds up startup of subsequent windows that use preloaded theme resources.

Example

Use the .Wait() method with the PreloadThemeResource to use synchronous theme preload.

The following code sample preloads Data Grid and LayoutControl assemblies while a splashscreen is displayed:

using System.Windows;
using System.Threading;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.Grid;
using DevExpress.Xpf.Layout;

static Type[] types;
    static App()
    {
        types = new Type[] { typeof(GridControl), typeof(LayoutControl) };
        SplashScreenManager.CreateThemed().ShowOnStartup();
        ThemeManager.PreloadThemeResource("Office2019Colorful");
    }

View Example