가능한 중복 :
How to make a Style that only exists within the context of a ResourceDictionary'비공개'ResourceDictionary를 만들려면 어떻게해야합니까?
내가있는 ResourceDictionary를 포함하는 프로젝트를 내가 공유 할 ControlTemplates를 노출하는 복잡한 ResourceDictionary에 짓고 있어요. 그러나이 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 내가 공개적으로 원하는 "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">
...
ResourceDictionary2는 ResourceDictionary1에 종속됩니다. 그것 없이는 컴파일되지 않으므로 작동하지 않습니다. 또한, 응용 프로그램 MergedDictionaries에 ResourceDictionary1을 포함하면 아무 것도 해결하지 못합니다. ResourceDictionary1의 모든 스타일은 모든 창에서 공개적으로 사용할 수 있습니다. ResourceDictionary2에서만 사용할 수 있기를 바랍니다. – Alain
ResourceDictionary1에 대한 참조를 ResourceDictionary2에 추가 할 수 있습니다. –
그것은 리소스를 어떻게 추가 할 수 있는지에 대한 참고서 일뿐입니다. 원하는 곳에 언제든지 참조를 추가 할 수 있습니다. 업데이트 된 답변을 확인하십시오. –