2011-10-16 36 views
5

我想在基於Prism的WPF應用程序中使用.NET 4 SplashScreen。我通過將圖像上的構建動作設置爲SplashScreen來使用SpashScreen。如何在基於WPF Prism的應用程序中使用.NET 4 SplashScreen?

該應用程序用於繼續與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> 

但是在棱鏡應用中,我們不能有StartupUri。一切都在Bootstrapper中完成。

那麼我需要做些什麼來讓StartupUri能夠使SplashScreen工作?

更新1:完整的異常消息爲:

System.Resources.MissingManifestResourceException了未處理

消息=找不到適合於指定培養或中性培養的任何資源。在編譯時確保 「Application.g.resources」已正確嵌入或鏈接到 程序集「應用程序」,或者所有需要的衛星 程序集均可加載並完全簽名。

更新2: 我已想出了添加或刪除的StartupUri無所謂。重要的是我有一個額外的WPF窗口(App.xaml除外)或App.Resources標籤中的2個虛擬條目。

<Application.Resources> 
    <Style x:Key="Dummy"/> 
    <Style x:Key="Dummy1"/> 
</Application.Resources> 

如果我不這樣做,是不是在OBJ文件中創建的文件Application.g.resources,因此沒有嵌入可執行文件。 這個blog post引起了我的注意,添加了兩個虛擬資源條目。

更新3:

我的問題是關於MSDN論壇here回答鮑勃寶。此外,肯特似乎試圖指出我在同一個方向。

不要將圖像的構建操作設置爲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」 是項目中的一個圖像,而其 「生成操作」 是「資源」。

+2

一個完整的例子就是在那裏某處這裏的一個問題? – DeCaf

+0

@DeCaf我已經更新了這個問題。 –

回答

1

只需定義您自己的入口點,它首先顯示啓動畫面,然後引導棱鏡。在您的項目屬性中,將入口點設置爲您的自定義入口點。

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

     var bootstrapper = ...; 
     bootstrapper....; 
    } 
} 
+0

問題不在於定義入口點。 WPF會自動創建一個靜態Main(),它創建一個SplashScreen,然後啓動App(),在其中創建我的引導程序。問題是,如果我沒有指定StartupUri,出於某種原因,作爲資源嵌入的Spash屏幕的圖像不適用於SplashScreen實例。因此我的問題是:我應該手動執行StartupUri標記嗎? –

+0

您的飛濺圖像屬性設置爲「資源」時,*生成操作*? –

+0

Boogart編號構建操作設置爲啓動屏幕。 –

相關問題