Create your own Custom Splash Page
In WPF you can really easily create a basic splash page which is just an image, but it is a bit simple for most people.
In my application I want to display a marquee style progress bar, application version numbers that are generated off the Assembly version number, and perform any application start up, like validate a license.
So create yourself a WPF window SplashPage.xaml and implement your layout and any custom code that should run inside the splash page.
Implement a timer so the window will remain open for a period of time. When the timer ticks, if all the work is done, close and dispose of the timer and then close the splash window.
Place this code in your App.xaml.
[csharp]
public partial class App : Application
{
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public static void Main()
{
ShowSplashScreen();
YourWpfApp.App app = new YourWpfApp.App();
app.InitializeComponent();
app.Run();
}
protected static void ShowSplashScreen()
{
SplashPage splash = new SplashPage();
splash.ShowDialog();
splash.Close();
}
}
[/csharp]
The Problem
When you build the program you will get an error like:
Type 'YourWPfApp.App' already defines a member called 'Main' with the same parameter types
When you click on the error it will take you to a page App.g.cs, which contains a duplicate static Main() application entry point, that is generated by VisualStudio.
The Solution
- Go to the properties of the App.xaml page.
- Check the Build Action. It will be “Application Definition”
- Change the build action to “Page”
- Build the application
The application will now build. The App.g.cs file will be updated and when you look it will no longer contain the Main method.
Cheers
Thank you very much!
It’s so funny that I confused with Project property with xaml property,
I am noob that i didn’t realize a xaml will have property.
Succeed util second time to get here.
Thank you very much jcrawfor74 !! usefull for me in 2019! 🙂
Thank you for this information. It helped me.