3

Pack URI を使用して、App.xaml で参照されているアセンブリをアプリケーション (WPF) に使用させようとしています。私のソリューションには、いくつかのプロジェクトがあります。ベース アプリケーションには、App.xaml しかありません。これで参照アセンブリを使用したいと思います。

App.xaml Project 1 (ソリューション内) を使用して、基本プロジェクトを呼び出します。これは、App.xaml の関連部分です。

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MyProject.Project2;component/Themes/Generic.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

プロジェクト 2 には、Generic.xaml を含む "Themes" フォルダーがあります。Generic.xaml のスタイリングが使用されていないため、Pack URI を間違って実行していると確信しています (カスタム ウィンドウで既定のウィンドウをオーバーライドしていますが、現在は機能しません。アプリケーションは次のように表示されます)。デフォルトのウィンドウ スタイル、ウィンドウ内はすべて黒です)。

フォルダ階層:

MainFolder
    Project 1
        App.xaml
        bin
            Debug
                Application.exe
    Project 2
        Themes
            Generic.xaml

質問:

  1. 誰かがpack://application:,,,構文を説明できますか? これはどういう意味ですか?
  2. パック URI のどこが間違っていますか?

前もって感謝します。

4

3 に答える 3

1

理解した。MyProject.Project2 で、AssemblyInfo.cs に次のコードが必要であることが判明しました。

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page, 
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries)
)]
于 2012-11-15T16:16:14.573 に答える
1

,,, の後の Pack Uri の最初の項目は、アセンブリの名前です。次のように設定してください。

"pack://application:,,,/[ASSEMBLY name here];component/Themes/Generic.xaml"

于 2012-11-14T17:13:25.117 に答える
1

App.xaml ではなく、プロジェクト 2 にリソース ディクショナリを移動してみてください。

于 2012-11-15T14:09:53.270 に答える