我有一个 WPF 应用程序。
应用程序在 MainWindow.xaml
中运行时打开的页面,如 App.xaml
文件的 StartupUri 属性中所设置。这个页面打开很好。
但是,如果我尝试使用 Show 或 ShowDialog 方法打开任何其他窗口,我会在 InitializeComponent 中得到一个
方法说 IOException
“无法找到资源 'Window1.xaml'”
(或调用的任何文件)。我创建的每个窗口都会发生这种情况。我在网上搜索过,但所有解决方案似乎都在说“确保 App.xaml 的 StartupUri 属性正确”,而我的是,因此 MainWindow 打开。
知道发生了什么吗?
最佳答案
以上对我不起作用,但起作用的如下。打开 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 更改为完全限定的 URI。在我的例子中,我将我的 MainWindow.xaml
移动到了一个名为“Main”的文件夹中,因此将上面的 URI 更改为
StartupUri="Main/MainWindow.xaml"
解决了我的问题。
关于c# - WPF IOException 找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6518603/