2012-05-10 45 views
1

我无法使用四种模块的Prism 4.0应用程序获得按钮样式。下面是从XAML视图文件中的单词数按钮元素:棱镜中的动态资源

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

该应用程序生成并运行,但按钮的颜色不会出现。我在Shell模块的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中的一些样式,但裸模板应用程序仅使用这些样式来处理外壳程序集中的控件,因此上面显示的参数为“无”和“SourceAssembly”。

由于我试图定义在比外壳模块的其它模块使用的样式,添加以下ThemeInfo属性到Module的AssemblyInfo.cs中和Module2L

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

我尝试添加一个到App.xaml的ThemeDictionary扩展如下所示App.xaml &没有结果。

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

也尝试了包的URL像这样的App.xaml &得到“无法找到资源”错误。

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

对缺少什么有什么想法或想法?谢谢。

回答

0

更新:我通过技术支持从微软的Marc Rodman那里得到了答案。两个变化:

一个是在Generic.xaml,转变作风定义:

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

另一个变化是App.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>