Skip to main content
A newer version of this page is available. .
All docs
V21.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.v21.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

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 PreloadThemeResourceAsync method allows you to speed up the display time of subsequent windows. The method preloads theme resources for the control assemblies that are referenced on these windows. You can use the PreloadThemeResourceAsync method both synchronously and asynchronously

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.v21.1.dll and DevExpress.Xpf.PropertyGrid.v21.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;
    protected async override 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.

Perfromance

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

Example

To use synchronous theme preload, use the .Wait() method with the PreloadThemeResource.

The following code sample preloads Data Grid and LayoutControl assemblies while the Splashscreen Manager 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

See Also