預加載主題資源
當您將DevExpress WPF主題應用到應用程序時,控件會使用主題資源(默認樣式、模板、鍵)來更改它們的外觀。
WPF應用程序僅在即將顯示控件時加載控件的主題資源,因此依賴于DevExpress WPF主題的窗口可能需要更長的時間才能出現。
當應用程序的第一個窗口很輕(例如,登錄表單),而主應用程序窗口很重(它包含一個或多個控件)時,這種延長的顯示時間可能是至關重要的。在這種情況下,第一個窗口出現得很快,但是第二個窗口加載主題資源可能要花很長時間。
和方法允許您加快后續窗口的顯示時間,這些方法為在這些窗口上引用的控件程序集預加載主題資源。
更多信息請參考以下方法的備注:/ 。
設置屬性為true來啟用主題預加載。
異步主題資源預加載
如何使用
當應用程序的啟動窗口是輕量級的(比如登錄表單)時,異步主題預加載的效果最好,在這種情況下,您可以使用方法在用戶輸入登錄憑據時異步預加載第二個窗口的主題資源。
示例
下面的代碼示例創建靜態構造函數,并在應用程序啟動時異步預加載Office2019Colorful主題資源。
App.xaml.cs:
	
using System.Windows;
using System.Threading;
using DevExpress.Xpf.Core;
public partial class App : Application {
static App() {
CompatibilitySettings.AllowThemePreload = true;
}
protected async override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
await ThemeManager.PreloadThemeResourceAsync("Office2019Colorful");
}
}
	
App.xaml.vb:
	
Imports System.Windows
Imports System.Threading
Imports DevExpress.Xpf.Core
Public Partial Class App
Inherits Application
Private Shared Sub New()
CompatibilitySettings.AllowThemePreload = True
End Sub
Protected Async Overrides Sub OnStartup(ByVal e As StartupEventArgs)
MyBase.OnStartup(e)
Await ThemeManager.PreloadThemeResourceAsync("Office2019Colorful")
End Sub
End Class
	
問題
異步主題資源預加載可能會減慢UI線程的資源加載速度。
同步主題資源預加載
何時使用
當您在應用程序啟動時顯示閃屏管理器時,此技術效果最佳。在這種情況下,該方法在顯示閃屏時會加載控件的主題資源。
表現
主題預加載會減慢應用程序的啟動速度,但會加快使用預加載主題資源的后續窗口的啟動速度。
示例
調用方法來同步預加載主題資源。
下面的代碼示例在顯示閃屏管理器時預加載Data Grid和LayoutControl程序集:
App.xaml.cs:
	
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");
}
}
	
App.xaml.vb:
	
Imports DevExpress.Xpf.Core
Imports DevExpress.Xpf.Grid
Imports DevExpress.Xpf.LayoutControl
Imports System
Imports System.Runtime.CompilerServices
Imports System.Windows
Public Partial Class App
Inherits Application
Shared types As Type()
Private Shared Sub New()
CompatibilitySettings.AllowThemePreload = True
PreloadThemes()
End Sub
<MethodImpl(MethodImplOptions.NoInlining)>
Private Shared Sub PreloadThemes()
types = New Type() {GetType(GridControl), GetType(LayoutControl)}
SplashScreenManager.CreateThemed().ShowOnStartup()
ThemeManager.PreloadThemeResource("Office2019Colorful")
End Sub
End Class
	

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線