Skip to main content

SplashScreenService Class

Allows you to display splash screens.

Namespace: DevExpress.Mvvm.UI

Assembly: DevExpress.UI.Xaml.v21.2.dll

NuGet Package: DevExpress.Uwp.Controls

Declaration

public class SplashScreenService :
    ViewServiceBase,
    ISplashScreenService

Remarks

You can use splash screens to provide an end-user with information about the progress of certain processes in your application.

SplashScreenGif

To add a splash screen to the application, define the SplashScreenService in the Interaction.Behaviors collection.

xmlns:dxmvvmui="using:DevExpress.Mvvm.UI"
xmlns:dxmvvmi="using:DevExpress.Mvvm.UI.Interactivity"

<dxmvvmi:Interaction.Behaviors>
    <dxmvvmui:SplashScreenService />    
</dxmvvmi:Interaction.Behaviors>

Then, access the attached SplashScreenService in your ViewModel by using the ViewModelBase.GetService method and invoke the ISplashScreenService.ShowSplashScreen method to show the splash screen.

public class MainViewModel : ViewModelBase {

    public ICommand ShowSplashScreenCommand { get; private set; }

    public ISplashScreenService DefaultSplashScreenService {
        get {
            return this.GetService<ISplashScreenService>();
        }
    }

    public MainViewModel() {
        ShowSplashScreenCommand = new DelegateCommand(OnShowSplashScreenCommandExecute);        
    }

    private async void OnShowSplashScreenCommandExecute() {
        DefaultSplashScreenService.ShowSplashScreen();
        await Task.Delay(4000);
        DefaultSplashScreenService.HideSplashScreen();
    }
}

Use the SplashScreenService.SplashScreenType property to specify the type of view containing a splash screen that needs to be shown.

Important

SplashScreenService works only when the DXFrame or HamburgerMenuFrame is used.

Example

<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:dxmvvmui="using:DevExpress.Mvvm.UI"
    xmlns:dxmvvmi="using:DevExpress.Mvvm.UI.Interactivity"
    mc:Ignorable="d">

    <Page.DataContext>
        <local:MainViewModel/>
    </Page.DataContext>

    <dxmvvmi:Interaction.Behaviors>
        <dxmvvmui:SplashScreenService Name="DefaultSplashScreen" />
        <dxmvvmui:SplashScreenService Name="ProgressBarSplashScreen" 
                                      SplashScreenType="dxmvvmui:ProgressBarSplashScreenView"/>
    </dxmvvmi:Interaction.Behaviors>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
        <StackPanel Orientation="Horizontal" 
                    VerticalAlignment="Center" 
                    HorizontalAlignment="Center">
            <Button Content="Show Default Splash Screen" 
                    Command="{Binding ShowSplashScreenCommand}" 
                    Margin="0,0,30,0"/>
            <Button Content="Show ProgressBar Splash Screen" 
                    Command="{Binding ShowProgressBarSplashScreenCommand}" />
        </StackPanel>
    </Grid>
</Page>
using DevExpress.Mvvm;
using System.Threading.Tasks;
using System.Windows.Input;

namespace App1 {
    public class MainViewModel : ViewModelBase {

        public ICommand ShowSplashScreenCommand { get; private set; }
        public ICommand ShowProgressBarSplashScreenCommand { get; private set; }
        public ISplashScreenService DefaultSplashScreenService {
            get {
                return this.GetService<ISplashScreenService>("DefaultSplashScreen");
            }
        }
        public ISplashScreenService ProgressBarSplashScreenService {
            get {
                return this.GetService<ISplashScreenService>("ProgressBarSplashScreen");
            }
        }

        public MainViewModel() {
            ShowSplashScreenCommand = new DelegateCommand(OnShowSplashScreenCommandExecute);
            ShowProgressBarSplashScreenCommand = new DelegateCommand(OnShowProgressBarSplashScreenCommandExecute);
        }

        private async void OnShowSplashScreenCommandExecute() {
            DefaultSplashScreenService.ShowSplashScreen();
            await Task.Delay(4000);
            DefaultSplashScreenService.HideSplashScreen();
        }

        private async void OnShowProgressBarSplashScreenCommandExecute() {
            ProgressBarSplashScreenService.ShowSplashScreen();

            ProgressBarSplashScreenService.SetSplashScreenState("Loading...");
            ProgressBarSplashScreenService.SetSplashScreenProgress(20, 100);
            await Task.Delay(2000);
            ProgressBarSplashScreenService.SetSplashScreenState("Initializing...");
            ProgressBarSplashScreenService.SetSplashScreenProgress(80, 100);
            await Task.Delay(2000);
            ProgressBarSplashScreenService.SetSplashScreenState("Finishing...");
            ProgressBarSplashScreenService.SetSplashScreenProgress(100, 100);
            await Task.Delay(2000);
            ProgressBarSplashScreenService.HideSplashScreen();
        }
    }
}

Inheritance

Object
DependencyObject
DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
DevExpress.Mvvm.UI.Interactivity.Behavior
DevExpress.Mvvm.UI.Interactivity.Behavior<FrameworkElement>
DevExpress.Mvvm.UI.ServiceBaseGeneric<FrameworkElement>
ServiceBase
ViewServiceBase
SplashScreenService
See Also