Sheen Space

Posts Tagged ‘WPF

Start-up process of WPF application

leave a comment »

This is my WPF study note. I don’t guarantee it is error-free. Please kindly post comment when you think anything is wrong.

There is a top-level user-defined application class derived from System.Windows.Application. Let’s call it MyApp. After compilation, C# compiler generates two functions for MyApp class:

  • static void Main()
  • void  InitializeComponent()

Compiler prohibits you from defining the same functions.

MyApp.Main() calls MyApp.InitializeComponent(), and then calls System.Windows.Application.Run().

MyApp.InitializeComponent() has information of XAML file of main window of the application, and calls System.Windows.Application::set_StartupUri() with the XAML file path. It knows the XAML file path of main window because the file path is specified in <Application/StartupUri> in MyApp.xaml.

System.Windows.Application.Run() executes like normal WinForm code, initialising the main window and entering window message loop.

Advertisements

Written by Ying

23/05/2012 at 00:09

Posted in DotNet, Technology, Windows

Tagged with ,