<分区>
Possible Duplicate:
How to make a Style that only exists within the context of a ResourceDictionary
我正在构建一个复杂的 ResourceDictionary,它将公开我想与包含该 ResourceDictionary 的项目共享的 ControlTemplate。但是,此 ResourceDictionary 包含一系列我不希望项目可用的支持样式和模板。我该怎么做?
例如:
<ResourceDictionary>
<!-- Private dictionary items used to set up the publicly usable Omnibox templates -->
<ResourceDictionary x:Key="PrivateDictionary">
<Thickness x:Key="BaseValueMarginAdjustment">2,0,0,0</Thickness>
<!--Base Styles -->
<Style x:Key="BaseElement" TargetType="FrameworkElement">...</Style>
<Style x:Key="GridStyle" TargetType="Grid" BasedOn="{StaticResource BaseElement}">...</Style>
<Style TargetType="Selector" x:Key="SelectorStyle" BasedOn="{StaticResource BaseElement}">...</Style>
...
</ResourceDictionary>
<!--Public CONTROL TEMPLATES -->
<ControlTemplate TargetType="{x:Type local:OmniBox}" x:Key="OBListBoxTemplate">
<Grid x:Name="PART_Grid" Style="{StaticResource GridStyle}">
<ListBox x:Name="PART_Value" Style="{StaticResource SelectorStyle}" />
...
</ControlTemplate>
<ControlTemplate ...>
...
</ResourceDictionary>
请注意,上面的方法不起作用。特别是,上面的编译,但有一个运行时错误,因为我想要公开可见的 ControlTemplates 找不到上面的私有(private)样式,如“GridStyle”。
尝试了以下方法也没有成功:
<ResourceDictionary>
<!-- Private dictionary items used to set up the publicly usable Omnibox templates -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>...</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<!--CONTROL TEMPLATES -->
<ControlTemplate TargetType="{x:Type local:OmniBox}" x:Key="OBTextBoxTemplate">
...