Splash Screen Manager
- 5 minutes to read
The SplashScreenManager allows you to add splash screens to your applications. Splash screens can be displayed during a time-consuming task such as application startup.
Splash Screen Appearance and Content
Predefined Styles
The following methods create a splash screen with a predefined style:
-
The color scheme for this splash screen is generated based on the application’s theme.
-
This splash screen uses an acrylic background from Fluent Design.
-
A compact loading indicator that displays text specified by the Status property.
Content
To specify the splash screen content, pass a DXSplashScreenViewModel as the Create method parameter. See the example below.
SplashScreenManager.CreateThemed(new DXSplashScreenViewModel {
Copyright = "All rights reserved",
IsIndeterminate = true,
Logo = new System.Uri("pack://application:,,,/Images/MyLogo.png",
UriKind.RelativeOrAbsolute),
Status = "Starting...",
Title = "",
Subtitle = "Powered by DevExpress" }
).ShowOnStartup();
You can also access the ViewModel and edit its properties. Use this approach to change the content of an active splash screen. The example below illustrates how to change the progress bar value.
void Calculate() {
var manager = SplashScreenManager.CreateThemed(new DXSplashScreenViewModel {
IsIndeterminate = false});
manager.Show();
for(int i = 0; i <= 100; i++) {
//Calculate the progress
manager.ViewModel.Progress = i;
}
manager.Close();
}
Use the DXSplashScreenViewModel.Tag property to specify the additional data associated with the view model instance. The example below illustrates how to pass a custom object to the splash screen:
SplashScreenManagerService.ViewModel = new DXSplashScreenViewModel() {
Tag = new CustomDataSplashScreenViewModel() {
Caption = "Custom Caption",
Message = "Custom Message"
}
};
SplashScreenManagerService.Show();
//...
public class CustomDataSplashScreenViewModel : ViewModelBase {
public string Caption {
get { return GetValue<string>(nameof(Caption)); }
set { SetValue(value, nameof(Caption)); }
}
public string Message {
get { return GetValue<string>(nameof(Message)); }
set { SetValue(value, nameof(Message)); }
}
}
<dx:WaitIndicator DeferedVisibility="True" Content="{Binding Path=.}">
<dx:WaitIndicator.ContentTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Tag.Caption}" FontSize="20"/>
<TextBlock Text="{Binding Tag.Message}"/>
</StackPanel>
</DataTemplate>
</dx:WaitIndicator.ContentTemplate>
</dx:WaitIndicator>
Custom Style
Use the Create method to create a custom splash screen. Refer to the How to: Create a Custom Splash Screen tutorial for more information.
Show Splash Screen
Tip
To test the performance of the Splash Screen that you display on application startup, run your application without attaching the debugger (Ctrl + F5).
The Show method displays the created splash screen. The ShowOnStartup method calls the Show method with the following parameters for a startup splash screen:
Show(
owner:null,
startupLocation:WindowStartupLocation.CenterScreen,
trackOwnerPosition:true,
inputBlock:InputBlockMode.None,
timeout:700);
At Startup
To display a splash screen at the application startup, add the following code to the App.xaml.cs/Application.xaml.vb:
Tip
If you apply the application’s theme in App.xaml.cs/Application.xaml.vb, specify it before showing a themed splash screen.
App() {
ApplicationThemeHelper.ApplicationThemeName = Theme.Office2019DarkGrayName;
SplashScreenManager.CreateThemed().ShowOnStartup();
}
On Demand
To display a splash screen on top of a UI element, pass the element as the owner parameter and set the startupLocation parameter to CenterOwner. Set the trackOwnerPosition parameter to true to keep the splash screen above the owner when the user drags the owner.
The example below illustrates how to display a wait indicator when the user navigates a HamburgerMenu.
private void HamburgerMenu_Navigating(object sender, DevExpress.Xpf.WindowsUI.HamburgerMenuNavigatingEventArgs e) {
SplashScreenManager.CreateWaitIndicator().Show((hamburgerMenu.Content as FrameworkElement),
WindowStartupLocation.CenterOwner, true, InputBlockMode.Owner);
}
Prevent the Splash Screen from Showing Too Briefly
Use the combination of the following parameters of the Show method:
- showDelay - The delay after which the splash screen is shown. If the associated operation completes faster than the parameter value, the splash screen will not be displayed.
- minDuration - The splash screen is shown for at least the value of this parameter.
The splash screen window should be a SplashScreenWindow descendant to support the showDelay and minDuration parameters.
Hide Active Splash Screens
To automatically hide the splash screen once the application is initialized, use the ShowOnStartup method with the autoClose parameter set to true.
To hide all active splash screens, call the CloseAll method. You can also access the ActiveSplashScreens collection and use the Close method to hide a specific splash screen.
private void Window_Loaded(object sender, RoutedEventArgs e) {
SplashScreenManager.CloseAll();
}
MVVM
The SplashScreenManagerService allows you to add the SplashScreenManager functionality to MVVM-compliant applications. Refer to the SplashScreenManagerService topic for more information.