【问题标题】:How to use .NET 4 SplashScreen in a WPF Prism based application?如何在基于 WPF Prism 的应用程序中使用 .NET 4 SplashScreen?
【发布时间】: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 我已经更新了问题。

标签: c# .net wpf prism


【解决方案1】:

只需定义您自己的入口点,首先显示启动屏幕,然后引导 Prism。在您的项目属性中,将入口点设置为您的自定义入口点。

internal static class Entry
{
    public static void Main(string[] args)
    {
        var splashScreen = ...;
        splashScreen.Show();

        var bootstrapper = ...;
        bootstrapper....;
    }
}

【讨论】:

  • 问题不在于定义入口点。 WPF 自动创建一个静态 Main(),它创建一个 SplashScreen,然后启动 App(),我在其中创建我的引导程序。问题是,如果我不指定 StartupUri,由于某种原因,作为资源嵌入的闪屏的图像对 SplashScreen 实例不可用。因此我的问题是:我应该像 StartupUri 标签那样手动做什么?
  • 您的初始图像属性上的 Build Action 是否设置为 Resource?
  • Boogart No. 构建操作设置为启动画面。
【解决方案2】:

请查看此地址:http://prismsplashscreen.codeplex.com/ prism有一个完整的例子

【讨论】:

    猜你喜欢
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 1970-01-01
    • 2014-06-13
    相关资源
    最近更新 更多