If you have ever looked at generated code (*.g.cs) located in obj
folder for any WPF project, there will be a call to InitializeComponent
- which loads the corrresponding XAML by calling LoadComponent
.
Quoting a sample from the MSDN page Application Management Overview
// Create new instance of application subclass
App app = new App();
// Code to register events and set properties that were
// defined in XAML in the application definition
app.InitializeComponent();
// Start running the application
app.Run();
So, you need call InitializeComponent
on app object after instantiate.
I am also adding InitializeComponent
code fro app.g.cs for one of my sample apps:
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent() {
#line 4 "..\..\..\App.xaml"
this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
#line default
#line hidden
}