【发布时间】:2012-08-18 10:33:14
【问题描述】:
在我的应用程序中,我有一个ContentControl,这显示了使用DataTemplates 的Content 属性。
现在,我需要将此 DictionaryResource 传递给 content 属性。所以我这样做了(我不确定)
<ContentControl Content="{Binding CurrentViewModel">
<ContentControl.Resources>
<ResourceDictionary Source="/MathematicsBusiness.Infrastructure;component/Resources/ThemeResources.xaml" />
</ContentControl.Resources>
</ContentControl>
这包含我的字典:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="40" />
<Setter Property="FontFamily" Value="Georgia" />
</Style>
<!--<Style x:Key="TextBlockStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="40" />
<Setter Property="FontFamily" Value="Georgia" />
</Style>-->
</ResourceDictionary>
而且它有效,所有数据模板都显示具有该样式的文本块。但是如果我使用注释样式,它就不起作用。它给我一个错误:
找不到具有名称/键 TextBlockStyle 的资源
为什么会这样?如果样式没有键,它可以工作。但是如果我设置一个键,它就不起作用了。
【问题讨论】:
-
您能否举例说明您是如何使用
TextBlockStyle键的?
标签: silverlight xaml styles silverlight-5.0 resourcedictionary