如何在基于WPF Prism的应用程序中使用.net 4 SplashScreen
本文关键字:net SplashScreen 应用程序 Prism WPF | 更新日期: 2023-09-27 18:11:37
我正在尝试在基于Prism的WPF应用程序中使用。net 4 SplashScreen。我通过将图像上的构建操作设置为SplashScreen来使用SpashScreen。
使用System.Resources.MissingManifestResourceException
的应用程序一直崩溃。最后我发现,如果我添加一个StartupUri="MainWindow。在App.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。一切都在Bootstrapper中完成
那么我需要手动做什么,StartupUri做了使SplashScreen工作?
Update 1:完整的异常消息为:
更新2:System.Resources。MissingManifestResourceException未处理
消息=找不到适合指定区域性或中性区域性的任何资源。确保"Application.g。资源"被正确嵌入或链接到程序集"应用程序"在编译时,或所有的卫星所需的程序集是可加载的,并且是完全签名的。
我已经发现添加或删除StartupUri并不重要。重要的是,我有一个额外的WPF窗口(除了App.xaml)或2个虚拟条目在App.Resources标签。
<Application.Resources>
<Style x:Key="Dummy"/>
<Style x:Key="Dummy1"/>
</Application.Resources>
如果我不这样做,application .g.r ures文件不会在obj文件中创建,因此不会嵌入到可执行文件中。添加两个虚拟资源条目是由这篇博客文章引起我的注意的。
更新3:我的问题在MSDN论坛上被Bob Bao回答了。而且肯特似乎也在试图给我指出同样的方向。
不要将映像的生成动作设置为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"资源是" "
。
简单地定义你自己的入口点,首先显示启动屏幕,然后引导Prism。在您的项目属性中,将入口点设置为您的自定义入口点。
internal static class Entry
{
public static void Main(string[] args)
{
var splashScreen = ...;
splashScreen.Show();
var bootstrapper = ...;
bootstrapper....;
}
}
请查看此地址:http://prismsplashscreen.codeplex.com/有一个完整的例子,prism