2016-07-07 166 views
1

我剛剛開始WPF。我從後面的代碼分配startupURI頁面。它給我這個錯誤:找不到資源'application_startup'

Cannot locate resource 'application_startup'"

這裏是我在App.xaml中做

<Application x:Class="HelloWpf.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     StartupUri="Application_Startup"> 
<Application.Resources> 

</Application.Resources> 

以下是我在App.xaml.cs文件已完成:

private void Application_Startup(object sender, StartupEventArgs e) 
    { 
     // Create the startup window 
     MainWindow wnd = new MainWindow(); 
     // Do stuff here, e.g. to the window 
     wnd.Title = "Something else"; 
     // Show the window 
     wnd.Show(); 

     //Application.Current.MainWindow = wnd; 
     //wnd.InitializeComponent(); 
     //wnd.Show(); 
    } 

請幫助這個簡單的代碼有什麼問題。謝謝

+4

事件名稱是'Startup',而不是'StartupUri'(即一個屬性)。正確訂閱處理程序:'Startup =「Application_Startup」' – ASh

+0

that worked.thanks .. –

回答

3

StartupUri用於指定應用程序啓動時要加載的窗口對象的文件名。 Startup是訂閱的事件,如果您想在應用程序啓動過程中執行某些操作。

2

將您的xaml更改爲以下代碼。它應該工作。

<Application x:Class="HelloWpf.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Startup="Application_Startup"> 
<Application.Resources> 

</Application.Resources>