在我的应用程序中,我有一个ContentControl
,这显示了Content
使用DataTemplates
.
现在,我需要将它传递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 的资源
为什么会这样?如果样式没有键,它可以工作。但是如果我设置一个键,它就不起作用。