Create a custom Main method for WPF application

When you create a new WPF Project the project template will create an App.xaml for you. Since WPF does a little magic behind the scenes, there is no way to access the Main method of your application. In this case, you simply delete the App.xaml and create a new App.cs class with the following code:

public class App : System.Windows.Application
        public Application()
            StartupUri = new Uri("Window1.xaml", UriKind.Relative);

        public static void Main()
            Application app = new Application();

private static void EnsureApplicationResources()

        // merge in your application resources



                new Uri("CustomAppTest;component/Resources/App.xaml",

                UriKind.Relative)) as ResourceDictionary);





~ by Martin on January 8, 2009.

4 Responses to “Create a custom Main method for WPF application”

  1. It was nice to see your blog.Just Keep Writing!

    Don’t pay for your electricity any longer…
    Instead, the power company will pay YOU!

  2. интересно было прочитать.

  3. This is not required.
    You should change the build action of App.xaml to Page, add a Program.cs and a Main, then from the project properties select the Program class as the startup.

  4. Thanks for wheiging in and I couldn’t agree with you more Dennis. That’s specifically why I mentioned the idea of getting a few advisors who are potential CEOs, it’s a wonderful way to see how you work together. Click

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: