我不能得到一个按钮风格的工作在一个棱镜4.0应用程序四个模块。以下是Module2中xaml视图文件中的按钮元素:
<Button Name="add" Width ="60" Style="{DynamicResource Red}" Click="add_Click"> Add</Button>
该应用程序构建和运行,但按钮的颜色没有出现。我已经在Shell模块的主题文件夹中的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统一模板提供的原始设置,由David的博客[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属性添加到AssemblyInfo.cs of Module1和Module2L中
[`assembly: ThemeInfo(ResourceDictionaryLocation.ExternalAssembly, ResourceDictionaryLocation.ExternalAssembly)]`
我尝试在ThemeDictionary中向App.xaml添加一个App.xaml扩展&没有结果。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="{ThemeDictionary MyApp}"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
还在App.xaml中尝试了这样的包url & got“无法定位资源”错误。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyApp;Shell/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
对于缺少什么,有什么想法或想法吗?谢谢。
发布于 2012-05-16 11:03:24
更新:我是通过技术支持从微软的Microsoft那里得到答案的。两个变化:
其中之一是在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>
https://stackoverflow.com/questions/10528847
复制