2012-05-10 4 views
1

4つのモジュールを持つPrism 4.0アプリでボタンスタイルを使用することはできません。ここではモジュール2でのXAMLビューファイルからボタン要素である:プリズム内の動的リソース

<Button Name="add" Width ="60" Style="{DynamicResource Red}" Click="add_Click"> Add</Button> 

アプリのビルドと実行されますが、ボタンの色が表示されません。シェルモジュールのThemesフォルダにあるGeneric.xamlファイルのスタイルを定義しました。これは、モジュール間で共有されるスタイルを配置できる場所になっているはずです。 Generic.xamlファイルでは私が持っている:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:Shell.Controls" 
    xmlns:wc="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"> 

<Style 
    x:Key="{ComponentResourceKey 
    TypeInTargetAssembly={x:Type wc:Button}, 
    ResourceId=Red}" 
    TargetType="wc:Button"> 
    <Setter Property="Foreground" Value="Red" /> 
    </Style> 
</ResourceDictionary> 

私はまた、シェルプロジェクトのプロパティフォルダにAssemblyInfo.csファイルで必要な基準を持っています。これは、プリズムGeneric.xamlファイルからすべてのスタイル参照を解決するためにプリズムアプリに指示する必要があります

[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] 

は、それらはデイヴィッド・ヒルさんが提供する、まだ私が開始されたとプリズムWPFユニティテンプレートによって提供されたオリジナルの設定ですブログ[http://blogs.msdn.com/b/dphill/archive/2011/01/16/prism-4-0-template-pack-now-available.aspx]。テンプレートにはすでにGeneric.xamlにいくつかのスタイルが付属していましたが、裸のテンプレートアプリケーションはシェルアセンブリ内のコントロールのスタイルしか使用しませんでした。したがって、上記の "None"と "SourceAssembly"のパラメータです。私はシェルモジュール以外のモジュールで使用するスタイルを定義しようとしていますので

は、私が追加しようとしたのModule1のAssemblyInfo.csとModule2L

[`assembly: ThemeInfo(ResourceDictionaryLocation.ExternalAssembly, ResourceDictionaryLocation.ExternalAssembly)]` 

に次のThemeInfo属性を追加しましたApp.xamlへのThemeDictionary拡張App.xamlのこのように&結果はありません。

<Application.Resources> 
    <ResourceDictionary> 
    <ResourceDictionary.MergedDictionaries> 
    <ResourceDictionary Source="{ThemeDictionary MyApp}"/> 
    </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
    </Application.Resources> 

はまた、「リソースを見つけることができません」エラーを得たApp.xaml &にこのようなパックのURLを試してみました。

<Application.Resources> 
    <ResourceDictionary> 
    <ResourceDictionary.MergedDictionaries> 
    <ResourceDictionary Source="pack://application:,,,/MyApp;Shell/Themes/Generic.xaml"/> 
    </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
    </Application.Resources> 

何か不足していることについての考えや考え方はありますか?ありがとうございました。

答えて

0

更新:テクニカルサポートを通じてMicrosoftのMarc Rodmanから回答を得ました。二つの変更:他の変更がApp.xamlにした

<Style 
x:Key="Red" 
TargetType="Button"> 
    <Setter Property="Foreground" Value="Red" /> 
    </Style> 

一つは、にスタイルの定義を変更し、Generic.xamlにあった

<Application.Resources> 

    <ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ResourceDictionary.MergedDictionaries> 
    <ResourceDictionary 
Source="pack://application:,,,/Shell;component/Themes/Generic.xaml"/> 
    </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
    </Application.Resources> 
関連する問題