WPF startup instance

WPF project is dynamic startup instance. What does this mean ?

[STAThread]
static void Main()
{
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Test());
}

classic windows form startup function

If your project is WPF application not have program.cs , WPF have (App.xaml and App.xaml.cs) 

<Application
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="BlogTestApplication.App"
 StartupUri="Test.xaml">
 <Application.Resources>
  <!-- Resources scoped at the Application level should be defined here. -->
 </Application.Resources>
</Application>

standart App.xmal source

look StartupUri="Test.xaml" is your WPF application startup instance WPF is dynamic generate main method if you want can change

StartupUri="Test2.xaml">

Other Method

namespace BlogTestApplication
{
 /// <summary>
 /// Interaction logic for App.xaml
 /// </summary>
 public partial class App : Application
 {


 }// class end
}

App.xaml.cs standart class structure

Add new method App.xaml.cs

namespace BlogTestApplication
{
 /// <summary>
 /// Interaction logic for App.xaml
 /// </summary>
 public partial class App : Application
 {

 void Main(object sender, StartupEventArgs e)
{
  Test ttWin = new Test();
  ttWin.Show();
 }

 }// class end
}

change App.xmal attribute

<Application
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="BlogTestApplication.App"
 Startup="Main">
 <Application.Resources>
  <!-- Resources scoped at the Application level should be defined here. -->
 </Application.Resources>
</Application>

set main method  startup attribute

Tags:

Leave a Reply