Back to Devexpress

Splash Screen Manager

wpf-401685-controls-and-libraries-windows-and-utility-controls-splash-screen-manager.md

latest10.4 KB
Original Source

Splash Screen Manager

  • Dec 29, 2023
  • 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.

Run Demo: Utility Controls - Splash Screen

Splash Screen Appearance and Content

Predefined Styles

The following methods create a splash screen with a predefined style:

Content

To specify the splash screen content, pass a DXSplashScreenViewModel as the Create method parameter. See the example below.

csharp
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();
vb
SplashScreenManager.CreateThemed(New DXSplashScreenViewModel With {
    .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.

csharp
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();
}
vb
Sub Calculate()
    Dim manager = SplashScreenManager.CreateThemed(New DXSplashScreenViewModel With {.IsIndeterminate = False})
    manager.Show()
    For i As Integer = 0 To 100
        'Calculate the progress
        manager.ViewModel.Progress = i
    Next i
    manager.Close()
End Sub

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:

csharp
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)); }
    }
}
vb
SplashScreenManagerService.ViewModel = New DXSplashScreenViewModel() With {
    .Tag = New CustomDataSplashScreenViewModel() With {
        .Caption = "Custom Caption",
        .Message = "Custom Message"
    }
}
SplashScreenManagerService.Show()

Public Class CustomDataSplashScreenViewModel
    Inherits ViewModelBase

    Public Property Caption() As String
        Get
            Return GetValue(Of String)(NameOf(Caption))
        End Get
        Set(ByVal value As String)
            SetValue(value, NameOf(Caption))
        End Set
    End Property
    Public Property Message() As String
        Get
            Return GetValue(Of String)(NameOf(Message))
        End Get
        Set(ByVal value As String)
            SetValue(value, NameOf(Message))
        End Set
    End Property
End Class
xaml
<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:

csharp
Show(
   owner:null,
   startupLocation:WindowStartupLocation.CenterScreen,
   trackOwnerPosition:true,
   inputBlock:InputBlockMode.None,
   timeout:700);
vb
Show(
   owner:=Nothing,
   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.

csharp
App() {
    ApplicationThemeHelper.ApplicationThemeName = Theme.Office2019DarkGrayName;
    SplashScreenManager.CreateThemed().ShowOnStartup();
}
vb
Private Sub New()
    ApplicationThemeHelper.ApplicationThemeName = Theme.Office2019DarkGrayName
    SplashScreenManager.CreateThemed().ShowOnStartup()
End Sub

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.

csharp
private void HamburgerMenu_Navigating(object sender, DevExpress.Xpf.WindowsUI.HamburgerMenuNavigatingEventArgs e) {
    SplashScreenManager.CreateWaitIndicator().Show((hamburgerMenu.Content as FrameworkElement),
        WindowStartupLocation.CenterOwner, true, InputBlockMode.Owner);
}
vb
Private Sub HamburgerMenu_Navigating(ByVal sender As Object, ByVal e As DevExpress.Xpf.WindowsUI.HamburgerMenuNavigatingEventArgs)
    SplashScreenManager.CreateWaitIndicator().Show((TryCast(hamburgerMenu.Content, FrameworkElement)),
        WindowStartupLocation.CenterOwner, True, InputBlockMode.Owner)
End Sub

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.

csharp
private void Window_Loaded(object sender, RoutedEventArgs e) {
    SplashScreenManager.CloseAll();
}
vb
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    SplashScreenManager.CloseAll()
End Sub

MVVM

The SplashScreenManagerService allows you to add the SplashScreenManager functionality to MVVM-compliant applications. Refer to the SplashScreenManagerService topic for more information.

See Also

Preload Theme Resources