Reputation: 3951
I'm trying to create an application that would use multiple windows. For starters I'd like it to have a splash screen window and a "main window". I came along this article: http://southworks.com/blog/2010/01/26/creating-a-multi-shell-application-in-prism-v2/ however it doesn't seem to suit my needs. Author is creating 2 windows at the same time, also showing both right from the start. What I want to do is to create this splash screen window (with some nice loading indicators) and only when it's underlying logic will complete its tasks, I want to show another window
protected override DependencyObject CreateShell() {
//return Container.Resolve<MainShell>();
return Container.Resolve<SplashScreenShell>();
}
protected override void InitializeShell() {
base.InitializeShell();
App.Current.MainWindow = (Window)Shell;
App.Current.MainWindow.Show();
}
Another issue is that when I use this code, all my modules (so even those used only by MainShell) are getting loaded and initialized, and that's totally not what I want. Mainly because Prism looks for RegionName that is not present on SplashScreenShell (but is present on the second shell).
I'm using Prism 6.1.0 and .NET 4.6.
Upvotes: 0
Views: 1866
Reputation:
Why not just show your splash screen before you call MainWindow.Show? Just show it as ShowDialog to stop the bootstrapper form continuing to process until you close your splash screen.
protected override void InitializeShell()
{
var sc = new SplashScreen();
sc.ShowDialog();
App.Current.MainWindow = (Window)Shell;
App.Current.MainWindow.Show();
}
Upvotes: 1
Reputation: 3448
The good patern is to stick to one window for the whole application. My proposal is to create splash screen as UserControl and then kind of mess around with visibility. Your MainView may be looking as follows
<Grid>
<ContentControl Content="{Binding CurrentViewModel}"/>
<userControl:SplashScreen/>
</Grid>
At this point your splash screen covers view and once the view is loaded you make the SplashScreen invisible. In order to do so create another class which will expose boolean property like IsVisible, and method Show/Hide for making splash screen visible and invisible respectively.
Subsequently, you set SplashScreen's DataContext to that class, bind Visibility property to IsVisible and make use of BooleanToVisibilityConverter, provided by WPF by default. For appearance sake, you can set splash sreen opacity to, for instance 0.75, so that it would show through splash screen displaying some destination view simultaneously.
Whenever you want to show splash screen you invoke Show method, within method you set IsVisible to true, PropertyChanged event is raised and changes are reflected at view. As a result Visibility is set to true and Splash screen shows up on the top covering everything else.
If you follow these steps you should acquire similar outcome. Message being displayed can be explicitly adjusted as well, as a replacement for hardcoded "Loading".
Upvotes: 1