DevExpress WPF 的 DXSplashScreen 控件在應用加載的時候顯示壹個啟動界面。添加DXSplashScreen後,會默認生成壹個XAML文件,當然,妳也可以根據自己的需求自定義XAML文件。
添加DXSplashScreen到項目中
1.右鍵單擊 Solution Explorer 中的項目,並選擇 Add DevExpress Item | New Item..
2.在彈出的 DevExpress Template Gallery 中單擊 DXSplashScreen 項目。
添加DXSplashScreen後,會生成壹個XAML文件。如果想自定義加載界面,修改XAML文件即可。
如何自動調用DXSplashScreen
DXSplashScreen可以在窗口加載時自動調用,然後在窗口初始化完畢後自動關閉,要實現這個功能,只需要在主窗口的XAML文件添加如下代碼:
1
dxc:DXSplashScreen.SplashScreenType="{x:Type local:SplashScreenWindow1}"
dxc 和 local聲明如下:
1
2
xmlns:local="clr-namespace:WpfApplication7"
xmlns:dxc="/winfx/2008/xaml/core"
但是這樣做有個缺陷就是無法控制進度條的進程,要控制進程,就要用另壹種方式:手動調用DXSplashScreen。
如何手動調用DXSplashScreen
妳也可以手動控制合適顯示和隱藏DXSplashScreen控件,這要通過DXSplashScreen類的壹個靜態方法來實現。
舉個例子,下面的代碼打開看壹個應用程序的加載界面:
下面的代碼關閉加載界面:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using DevExpress.Xpf.Core;
namespace WpfApplication7 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e) {
DXSplashScreen.Close();
this.Activate();
}
}
}
默認情況下,DXSplashScreen包含壹個進度條,表示應用程序加載的進度,下面的代碼就可以實現手動控制進度:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Developer Express Code Central Example:
// How to manually invoke and close DXSplashScreen
//
// This example shows how to manually invoke and close DXSplashScreen. By default,
// DXSplashScreen contains a progress bar, indicating the progress of the
// application load. This example also shows how you can manually change the
// progress in code.
//
// You can find sample updates and versions for different programming languages here:
// /example=E3243
using DevExpress.Xpf.Core;
using System.Windows;
namespace DXSplashScreenSample {
public partial class App : Application {
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
DXSplashScreen.Show<SplashScreenView>();
}
}
}