【发布时间】:2011-10-16 19:07:36
【问题描述】:
我正在尝试在基于 Prism 的 WPF 应用程序中使用 .NET 4 SplashScreen。我通过将图像上的构建操作设置为 SplashScreen 来使用 SpashScreen。
该应用程序过去常常因System.Resources.MissingManifestResourceException 而崩溃。最后我发现如果我在 App.Xaml 文件中添加 StartupUri="MainWindow.xaml",SplashScreen 工作正常。
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
</Application>
但是在 prism 应用程序中,我们不能有 StartupUri。一切都在引导程序中完成。
那么我需要手动执行什么 StartupUri 才能使 SplashScreen 工作?
更新1:完整的异常信息是:
System.Resources.MissingManifestResourceException 未处理
Message=找不到任何适合指定文化或中性文化的资源。确保 “Application.g.resources”已正确嵌入或链接到 汇编“应用程序”在编译时,或所有卫星 所需的程序集是可加载且完全签名的。
更新 2: 我发现添加或删除 StartupUri 并不重要。重要的是我在 App.Resources 标记中有一个额外的 WPF 窗口(App.xaml 除外)或 2 个虚拟条目。
<Application.Resources>
<Style x:Key="Dummy"/>
<Style x:Key="Dummy1"/>
</Application.Resources>
如果我不这样做,Application.g.resources 文件不会在 obj 文件中创建,因此不会嵌入到可执行文件中。 这个blog post 引起了我的注意,添加了两个虚拟资源条目。
更新 3:
Bob Bao 在 MSDN 论坛 here 上回答了我的问题。此外,Kent 似乎试图将我指向同一个方向。
不要将图像的构建操作设置为 SplashScreen。而是:
在App OnStartup方法中添加代码为:
protected override void OnStartup(StartupEventArgs e)
{
SplashScreen splashScreen = new SplashScreen("splashscreen.png");
splashScreen.Show(true);
base.OnStartup(e);
Bootstrapper bootstrapper = new Bootstrapper();
bootstrapper.Run();
}
“splashscreen.png”是项目中的一张图片,它的“Build Action” 是“资源”。
【问题讨论】:
-
这里有问题吗?
-
@DeCaf 我已经更新了问题。