【发布时间】:2017-09-18 07:26:36
【问题描述】:
我正在尝试将 WPF 应用程序中的 MainWindow 位置从默认启动 URI:MainWindow.xaml 更改为 Views\MainWindow .xaml. 其中Views 是在项目文件夹中创建的文件夹。
Uri:this.StartupUri = new System.Uri(@"Views\MainWindow.xaml", System.UriKind.Relative);
我更改了 uri,然后应用程序因以下错误而中断:
An unhandled exception of type 'System.TypeInitializationException'occurred in PresentationFramework.dll
Additional information: The type initializer for 'System.Windows.Application' threw an exception.
我在 Main 方法、InitializeComponent 方法和 MainWindow 构造函数中放置了断点和 try-catch 块,但无济于事。它崩溃了,我无法捕获异常。
主要:
public static void Main() {
try
{
wpfTest.App app = new wpfTest.App();
app.InitializeComponent();
app.Run();
}catch(Exception ex)
{
Console.WriteLine(ex.InnerException.Message);
}
}
startupUri 是否也必须在其他地方更改?它只有一个引用:InitializeComponent 方法中的那个。
【问题讨论】:
标签: c# wpf uri mainwindow typeinitializeexception