IOException异常无法找到资源

IOException异常无法找到资源

本文介绍了WPF IOException异常无法找到资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序。

I have a WPF application.

这是当应用程序在运行MainWindow.xaml,如在App.xaml文件的的StartupUri属性设置打开的页面。此页面打开罚款。

The page that opens when the app runs in MainWindow.xaml, as set in the StartupUri attribute of the App.xaml file. This page opens fine.

不过,如果我尝试打开使用Show或ShowDialog方法我在InitializeComponent方法获得一个IOException说任何其他窗口无法找到资源Window1.xaml'(或任何文件被调用)。这种情况与我创建的每一个窗口。我在网上搜索,但所有的解决方案,似乎在说确保App.xaml中的属性的StartupUri正确而我的,因此主窗口开放。

However, if I try to open any other windows using the Show or ShowDialog method I get an IOException in the InitializeComponent method saying "Cannot locate resource 'Window1.xaml'" (or whatever the file is called). This happens with every single window I create. I've searched online but all the solutions seem to say "make sure the StartupUri attribute of the App.xaml is correct" and mine is, hence MainWindow opening.

任何想法是怎么回事?

推荐答案

以上并没有为我工作,但做什么工作情况如下。打开的App.xaml

The above did not work for me but what did work was as follows. Open up the App.xaml

<Application x:Class="dotDiff2013.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>

您则需要在启动URI更改为完全合格的。在我来说,我搬到我的 MainWindow.xaml 来一个名为'主',所以改变上述URI来

You then need to change the start-up URI to the fully qualified one. In my case I had moved my MainWindow.xaml to a folder called 'Main', so changing the above URI to

StartupUri="Main/MainWindow.xaml"

解决我的问题。

这篇关于WPF IOException异常无法找到资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 11:49