Archive for the ‘WPF’ Category

Type ‘YourWPfApp.App’ already defines a member called ‘Main’ with the same parameter types

January 23rd, 2013 2 comments

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.

public partial class App : Application
	/// <summary>
	/// Application Entry Point.
	/// </summary>
	[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "")]
	public static void Main()
		YourWpfApp.App app = new YourWpfApp.App();

	protected static void ShowSplashScreen()
		SplashPage splash = new SplashPage();

The Problem

When you build the program you will get an error like:

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

  1. Go to the properties of the App.xaml page.
  2. Check the Build Action. It will be “Application Definition”
  3. Change the build action to “Page”
  4. 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.


VN:F [1.9.22_1171]
Rating: 10.0/10 (13 votes cast)

Categories: c#, WPF Tags:

How to make a Modal Dialog in WPF

October 23rd, 2012 No comments

The Scenario

I have created a c# WPF application. The app has an “About” page that I want to show as a modal dialog.

The Problem

The issue is when the “About” dialog is open and the user Alt+Tab’s the “About” dialog is visible as a separate tile in the Alt+Tab list. The about dialog also has a url link. Clicking this opens a browser window. When the user Alt+Tab’s back to the application the about dialog is visible whilst the calling app is now behind the web browser.


Firstly, in WPF create your dialog as a “Window” control.

In windows forms you would do:

  frmAbout about = new frmAbout();

In WPF its the same concept but syntactically slightly different:

  About aboutWindow = new About();
  aboutWindow.Owner = this;

This will open the window as a modal dialog.

One other setting to play with on the About window is WindowsStartUpLocation

  • CenterScreen
  • CenterOwner
  • Manual

Setting it as “CenterOwner” will open in the centre of the calling Window. I set mine to centre screen as it looked a bit funny starting centre of the owner.

VN:F [1.9.22_1171]
Rating: 4.2/10 (6 votes cast)

Categories: c#, WPF Tags: