Skip to main content
A newer version of this page is available. .

DXSplashScreenService (legacy)

  • 5 minutes to read

Note

You are viewing documentation for the legacy DXSplashScreen. We recommend that you use the Splash Screen Manager or the SplashScreenManagerService to add the splash screen functionality to your applications.

DXSplashScreenService is an ISplashScreenService implementation that allows you to display a splash screen with a custom view. This splash screen is being processed in a separate thread.

Getting Started with DXSplashScreenService

Assume that you need to show a complex splash screen view with several images, a progress bar and other elements, while a heavy and resource-intensive operation is being performed. This functionality is already built-in to the DXSplashScreen class. Designing an MVVM-compliant application must be accomplished without calling the DXSplashScreen methods from a View Model. For this purpose, utilize the DXSplashScreenService.

To use the DXSplashScreenService, add it to the Interaction.Behaviors collection. You can accomplish this task using Smart Tag as described in the Attaching MVVM Behaviors and Services or manually as shown in the code snippet below.

<UserControl x:Class="DXSampleSplashScreenService.View.MainView" 
    ...
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
    xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
    <dxmvvm:Interaction.Behaviors>
        <dx:DXSplashScreenService/>
    </dxmvvm:Interaction.Behaviors>
    ...
</UserControl>

To specify a splash screen view, add a default view from the Template Gallery (see How to: Add DXSplashScreen to Your Project for details) or implement your own based on a UserControl.

When a splash screen view is added, set the DXSplashScreenService.SplashScreenType property to the view’s type.

<dxmvvm:Interaction.Behaviors>
    <dx:DXSplashScreenService SplashScreenType="View:SplashScreenView"/>
</dxmvvm:Interaction.Behaviors>

Alternatively, you can define the splash screen view layout directly by using the ViewServiceBase.ViewTemplate property.

<dxmvvm:Interaction.Behaviors>
    <dx:DXSplashScreenService>
        <dx:DXSplashScreenService.ViewTemplate>
            <DataTemplate>
                <View:SplashScreenView/>
            </DataTemplate>
        </dx:DXSplashScreenService.ViewTemplate>
    </dx:DXSplashScreenService>
</dxmvvm:Interaction.Behaviors>

To show and hide the splash screen from your View Model, use the ISplashScreenService.ShowSplashScreen and ISplashScreenService.HideSplashScreen methods accordingly.

[POCOViewModel]
public class MainViewModel {
    protected ISplashScreenService SplashScreenService { get { return this.GetService<ISplashScreenService>(); } }
    public void Calculate() {
        SplashScreenService.ShowSplashScreen();
        ...
        SplashScreenService.HideSplashScreen();
    }
}

A detailed description on how to obtain a service from a View Model (which is a POCO object or a ViewModelBase descendant) is available here: Services in POCO objects and Services in ViewModelBase descendants.

Note

DXSplashScreenService does not support the simultaneous display of multiple splash screens.

If you need to show the splash screen automatically whenever a view is loading, set the DXSplashScreenService.ShowSplashScreenOnLoading property to True.

Injecting Custom Data to the shown DXSplashScreen

The DXSplashScreenService provides methods to inject your custom data into the splash screen: ISplashScreenService.SetSplashScreenState and ISplashScreenService.SetSplashScreenProgress. The ISplashScreenService.SetSplashScreenState method allows you to pass a secondary view model to the splash screen. By using the ISplashScreenService.SetSplashScreenProgress method, you can specify the splash screen bar progress value.

[POCOViewModel]
public class MainViewModel {
    protected ISplashScreenService SplashScreenService { get { return this.GetService<ISplashScreenService>(); } }
    public void Calculate() {
        SplashScreenService.ShowSplashScreen();
        SplashScreenService.SetSplashScreenState("Calculating...");
        ...
        SplashScreenService.SetSplashScreenState("Finished.");
        Thread.Sleep(TimeSpan.FromSeconds(2));
        SplashScreenService.HideSplashScreen();
    }
}

These methods pass data to the predefined SplashScreenViewModel instance located in the DXSplashScreen’s DataContext which has a set of properties that you can use in your splash screen with bindings.

public class SplashScreenViewModel : ViewModelBase, ISupportSplashScreen {
    public bool IsIndeterminate { ... }
    public double MaxProgress { ... }
    public double Progress { ... }
    public object State { ... }
}

For example, you can bind the splash screen View’s elements in the followings manner.

<UserControl x:Class="DXSampleSplashScreenService.View.SplashScreenView" ... >
    <Grid>
        <Border BorderBrush="#FF0072C6" BorderThickness="1" Margin="2">
            <Grid>
                <ProgressBar BorderThickness="0" Value="{Binding Progress}" Maximum="{Binding MaxProgress}" IsIndeterminate="{Binding IsIndeterminate}" Height="12" />
                <TextBlock Text="{Binding State}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Grid>
        </Border>
    </Grid>
</UserControl>

Customizing DXSplashScreen Appearance and Location

In addition to the capability to define a custom layout, you can customize the splash screen window by overriding the DXSplashScreenService.SplashScreenWindowStyle property. To change the splash screen location, use the DXSplashScreenService.SplashScreenStartupLocation property.

Example

Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.POCO
Imports DevExpress.Mvvm.DataAnnotations
Imports System
Imports System.Threading

Namespace DXSampleSplashScreenService.ViewModel
    <POCOViewModel> _
    Public Class MainViewModel
        Public Overridable Property Delay() As Integer
        Protected ReadOnly Property SplashScreenService() As ISplashScreenService
            Get
                Return Me.GetService(Of ISplashScreenService)()
            End Get
        End Property

        Public Sub New()
            Delay = 10
        End Sub

        Public Sub Calculate()
            SplashScreenService.ShowSplashScreen()
            SplashScreenService.SetSplashScreenState("Calculating...")
            Thread.Sleep(TimeSpan.FromSeconds(Delay))
            SplashScreenService.SetSplashScreenState("Finished.")
            Thread.Sleep(TimeSpan.FromSeconds(2))
            SplashScreenService.HideSplashScreen()
        End Sub
    End Class
End Namespace