2011-04-21 105 views
4

假設我們從具有App.xaml/cs,MainWindow.xaml/cs 的默認新WPF項目開始,應用程序執行這些代碼的順序是什麼。解析App.xaml - >運行App.xaml.cs - >解析MainWindow.xaml - >運行MainWindow.xaml.cs?以及如何在屬性中執行Resource.Designer.cs和Settings.Designer.cs?WPF如何啓動App.xaml/cs和MainWindow.xaml/cs

回答

4

每個dotnet應用程序(PE文件)都以一個入口點開始,該入口點通常是「Main」,但是在wpf中,您看不到這個,因爲studio隱藏了它的用戶,因爲它非常混亂。 一旦找到Main方法,您就會知道自己的執行流程。對於看下面的圖片 enter image description here

+0

btw,* .g.cs和* .g.i.cs有什麼區別? – demaxSH 2011-04-21 07:02:21

+0

我認爲g.ic.cs是生成g.cs.的模板。但不確定。也許你可以在這裏找到並編寫你的解決方案:) – crypted 2011-04-21 07:10:23

2

由於INT3用戶說,主要方法是位於App.g.cs和是這樣

public static void Main() { 
    YourAppNamespace.App app = new YourAppNamespace.App(); 
    app.InitializeComponent(); 
    app.Run(); 
} 

這意味着你會得到應用構造執行在別的之前。