2014-02-19 42 views
3

當我們創建從Visual Studio新WPF C#項目,我們得到4個基本文件"App.xaml","App.cs","MainWindow.xaml","MainWindow.cs"如何在Visual Studio中手動創建WPF Python項目中的App.xaml文件?

這裏App.xaml文件基本上是用於在一個文件中存儲application related Resources是目前遍佈應用。

但在Visual Studio創建WPF Python項目時,我們只能得到2個文件"MainWindow.xaml" and "MainWindow.py"

I want to create 2 more file in my Python project「的App.xaml」「App.py」使得"App.xaml"我可以輕鬆定義我的所有應用程序相關的資源樣式和控制模板。

Plz Help !!

回答

5

您可以從解決方案資源管理器中將應用程序文件添加到您的項目中。您可以按Alt + S將其打開。在解決方案資源管理器中,選擇您的項目,然後右鍵單擊並從彈出菜單中選擇添加菜單項,然後選擇新項目菜單項。

接下來,在安裝的模板添加新項對話窗口中,您可以選擇WPF左側篩選可用的模板。然後,您可以簡單地選擇添加資源字典並將其命名爲App.xaml。只要你把相關的代碼中,它會被罰款:

<Application x:Class="ManuallyCreatingAWpfProject.app" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Startup="AppStartup" 
    > 
    <Application.Resources> 

    </Application.Resources> 

</Application> 

... 

public partial class App : Application 
{ 
    void AppStartup(object sender, StartupEventArgs args) 
    { 
     Window1 mainWindow = new Window1(); 
     mainWindow.Show(); 
    } 
} 

此代碼從Walkthrough: Manually Creating a Windows Presentation Foundation Project Using Visual Studio頁面上MSDN,您也可能會發現有趣的拍攝。

您可能還需要去項目屬性(右鍵單擊在Solution Explorer中的項目並選擇屬性)和啓動對象設置爲App.xaml文件中應用標籤。最後,您最好在App.xaml文件屬性中將構建動作設置爲ApplicationDefinition

相關問題