Ghost1372

everything can be handy

SplashWindow

A Simple Dynamic Splash Screen.

Available Only in Custom Version

1
public class SplashWindow : HandyControl.Controls.Window, ISplashWindow, INotifyPropertyChanged

Case

First create a Windows (we call it MySplashWindow.xaml) and change <Window to <hc:SplashWindow

1
2
3
4
5
6
7
8
9
10
11
12
13
<hc:SplashWindow x:Class="HandyControlDemo.MySplashWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="Splash Window"
Height="450"
Width="800">

</hc:SplashWindow>
1
2
3
4
5
6
7
public partial class MySplashWindow : HandyControl.Controls.SplashWindow
{
public MySplashWindow()
{
InitializeComponent();
}
}

Now initialize the SplashWindow in App.cs and OnStartup method

1
2
3
4
5
6
7
8
protected override void OnStartup(StartupEventArgs e)
{
SplashWindow.Init(()=> {
MySplashWindow splash = new MySplashWindow();
return splash;
});
base.OnStartup(e);
}

Now to display messages in splash you can use the built-in Message property.
Be sure to connect the AncestorType to the hc:SplashWindow

1
2
3
4
5
6
7
8
9
10
11
12
13
<hc:SplashWindow x:Class="HandyControlDemo.MySplashWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="Splash Window"
Height="450"
Width="800">
<TextBlock Text="{Binding Message, RelativeSource={RelativeSource AncestorType=hc:SplashWindow}}"/>
</hc:SplashWindow>

Now do this to display splash and update messages

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public MainWindow()
{
SplashWindow.Instance.AddMessage("Loading main window");
DoSomethingThatTakesALongTime();
SplashWindow.Instance.AddMessage("Loading something Witty");
DoSomethingElseThatTakesALongTime();
//This will probably never actually get seen
SplashWindow.Instance.AddMessage("Done!");
InitializeComponent();
SplashWindow.Instance.LoadComplete();
}

private void DoSomethingElseThatTakesALongTime()
{
Thread.Sleep(2000);
}

private void DoSomethingThatTakesALongTime()
{
Thread.Sleep(2000);
}
0%