2016-07-07 163 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>