0
在我的申請中,我有一個ContentControl
,這顯示Content
財產使用DataTemplates
。如何將ResourceDictionary設置爲ContentControl.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>
和它的作品,所有的數據模板都顯示了與風格的TextBlocks。但是如果我使用評論風格,它不起作用。它給我一個錯誤:
Cannot find a Resource with the Name/Key TextBlockStyle
爲什麼會發生這種情況?如果該樣式沒有Key,則可以使用。但是如果我設置了一個鍵,它不起作用。
你能提供一個如何使用'TextBlockStyle'鍵的例子嗎? –