Control the entry point of WPF application

The app.main() is gone in default auto-gened WPF application, there are some workarounds to add customized startup app class. I found adding Startup attribute then implement startup eventhandler is a eaiser and clean solution:

Adding Startup property to App.xaml:

<Application x:Class="StakeholderDemo.Layers.WpfUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml"
Startup="App_StartUp"
StartupUri="MenuForm.xaml"
>
<Application.Resources>

</Application.Resources>
</Application>

Implement code:
public partial class App : Application
{
  void  App_StartUp(object sender, StartupEventArgs e)
  {
   //...;
  }
}
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s