#91 – What InitializeComponent() Does

The entry point into a WPF application, the Main function, is quite simple.  It creates an instance of your Application object, calls its InitializeComponent method and then its Run method.

The see the body of the Main function, as well as the body of InitializeComponent, do the following:

  • Build your application
  • Click on the Show All Files icon in the Solution Explorer

  • In Solution Explorer, navigate to App.g.cs file

Double-click to open App.g.cs.  You’ll see the body of Main.  You’ll also see the body of InitializeComponent.

public void InitializeComponent() {

    #line 4 "..\..\..\App.xaml"
    this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);

    #line default
    #line hidden
 }

This function merely sets properties on the Application object based on values that you set in App.xaml.  By default, this includes only setting the StartupUri property to point to the application’s main window.

Update, 20-Oct-2010: InitializeComponent() does a bit more when generated for a Window, rather than for an App. See What Visual Studio Does with Your XAML for details.

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #91 – What InitializeComponent() Does

  1. Pingback: Tweets that mention #91 – What InitializeComponent() Does « 2,000 Things You Should Know About WPF -- Topsy.com

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: