我无法在具有四个模块的 Prism 4.0 应用程序中使用按钮样式。这是 Module2 中 xaml 视图文件中的按钮元素:
<Button Name="add" Width ="60" Style="{DynamicResource Red}" Click="add_Click"> Add</Button>
应用程序构建并运行,但按钮颜色未出现。我在 Shell Module 的 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>
我在 Shell 项目的 Properties 文件夹中的 AssemblyInfo.cs 文件中也有必要的参考。这应该指示 Prism 应用程序从 Prism Generic.xaml 文件中解析所有样式引用:
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
这些仍然是我开始使用的 Prism WPF Unity 模板提供的原始设置,由 David Hill 的博客[http://blogs.msdn.com/b/dphill/archive/2011/01/16/prism- 4-0-template-pack-now-available.aspx]。该模板已经在 Generic.xaml 中附带了一些样式,但裸模板应用程序仅将这些样式用于 Shell 程序集中的控件,因此上面显示了参数“None”和“SourceAssembly”。
由于我试图定义用于除 Shell 模块以外的其他模块的样式,因此我将以下 ThemeInfo 属性添加到 Module1 和 Module2L 的 AssemblyInfo.cs
[`assembly: ThemeInfo(ResourceDictionaryLocation.ExternalAssembly, ResourceDictionaryLocation.ExternalAssembly)]`
我尝试在 App.xaml 中像这样向 App.xaml 添加 ThemeDictionary 扩展,但没有结果。
<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>
关于缺少什么的任何想法或想法?谢谢你。