找不到资源'application_startup'

Nee*_*ati 2 wpf

我刚刚开始WPF.我正在startupURI从代码后面分配页面.它给了我这个错误:

找不到资源'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>
Run Code Online (Sandbox Code Playgroud)

这是我在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();
    }
Run Code Online (Sandbox Code Playgroud)

请帮助这个简单的代码有什么问题.谢谢

Jai*_*Jai 6

StartupUri用于指定应用程序启动时要加载的窗口对象的文件名.Startup如果您想在应用程序启动期间执行某些操作,则订阅该事件.


ViV*_*iVi 5

将您的 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>
Run Code Online (Sandbox Code Playgroud)