Skip to main content
All docs
V24.1

ThemeManager.PreloadThemeResource(String, Boolean) Method

Preloads the specified theme and creates theme resources for all loaded assemblies.

Namespace: DevExpress.Xpf.Core

Assembly: DevExpress.Xpf.Core.v24.1.dll

NuGet Package: DevExpress.Wpf.Core

Declaration

public static void PreloadThemeResource(
    string themeName,
    bool runTypeInitializers = false
)

Parameters

Name Type Description
themeName String

A theme you want to preload.

Optional Parameters

Name Type Default Description
runTypeInitializers Boolean False

true to invoke static constructors; otherwise, false.

Remarks

Note

The PreloadThemeResource method executes the legacy theme preload mechanism. Use the ApplicationThemeHelper.Preload method instead.

Controls in an application 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, consequent 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 (login form), and the main application window is heavy (contains a massive control\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 PreloadThemeResource and PreloadThemeResourceAsync methods allow you to speed up the display time of subsequent windows. These methods preload theme resources for the control assemblies that are referenced on these windows.

Set the CompatibilitySettings.AllowThemePreload property to true to enable the theme preload.

Load Assemblies

If you need to preload theme resources for a control, ensure that the control’s assembly is loaded beforehand. If the control’s assembly references another assembly, the referenced assembly will be also preloaded.

To get the list of loaded assemblies, use the Debug Modules view.

The following code sample preloads the additionally loaded DevExpress.Xpf.Grid.v24.1.dll and DevExpress.Xpf.PropertyGrid.v24.1.dll assemblies and their dependencies:

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

public partial class App : Application {
    static Type[] types;
    static App() {
        CompatibilitySettings.AllowThemePreload = true;
    }
    protected override async void OnStartup(StartupEventArgs e) {
        base.OnStartup(e);

        types = new Type[] { typeof(GridControl), typeof(PropertyGrid) };
        await ThemeManager.PreloadThemeResourceAsync("Office2019Colorful");
    }
}

Synchronous Theme Resource Preload

When to Use

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

Performance

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

Example

Call the PreloadThemeResource method to preload theme resources synchronously.

The following code sample preloads Data Grid and LayoutControl assemblies while the Splashscreen Manager is displayed:

using DevExpress.Xpf.Core;
using DevExpress.Xpf.Grid;
using DevExpress.Xpf.LayoutControl;
using System;
using System.Runtime.CompilerServices;
using System.Windows;

public partial class App : Application {
    static Type[] types;
    static App() {
        CompatibilitySettings.AllowThemePreload = true;
        PreloadThemes();
    }
    [MethodImpl(MethodImplOptions.NoInlining)]
    static void PreloadThemes() {
        types = new Type[] { typeof(GridControl), typeof(LayoutControl) };
        SplashScreenManager.CreateThemed().ShowOnStartup();
        ThemeManager.PreloadThemeResource("Office2019Colorful");
    }
}

View Example: Synchronously Preload WPF Themes Within Splashscreen

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PreloadThemeResource(String, Boolean) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also