gpt4 book ai didi

c# - 为什么没有调用 Application.OnStartup?

转载 作者:可可西里 更新时间:2023-11-01 08:20:10 25 4
gpt4 key购买 nike

我有一个 WPF .NET 4 应用程序,我在其中覆盖了 OnStartup 方法以处理传递给我的应用程序的文件。但是,应用程序运行时似乎没有调用此方法。我在那里放了一个异常,甚至是一个断点,然后它启动并完全忽略了这一点。

我错过了什么吗?

App.xml.cs 的代码:

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
throw new NotImplementedException();
}
}

App.xaml 的内容:

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

</Application.Resources>
</Application>

编辑:找到了! App.xaml 中的 x:Class 属性与 App.xaml.cs 类不匹配 :) 这就是您边喝酒边编码的结果。 (感谢这个线程:WPF app startup problems)

最佳答案

找到了,我不得不将 App.xaml 中的 x:Class 属性设置为与 App.xaml.cs 类相同的类。这是我这边重构不当导致的错误。

关于c# - 为什么没有调用 Application.OnStartup?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5892842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com