2014-10-29 4 views
0

이 예제를 사용하려고합니다. 나는 새로운 WPF 사용자 정의 라이브러리 프로젝트를 제어 만든 내가 응용 프로그램에서 내 컨트롤을 사용할 때, 나는 TextBlock이 표시되지 않는ContentControl이 DynamicResource를 통해 템플릿을 선택하지 않습니다.

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="clr-namespace:WpfCustomControlLibrary1"> 

<ControlTemplate x:Key="myControlTemplate1"> 
    <TextBlock Text="This text should appear"></TextBlock> 
</ControlTemplate> 
<Style TargetType="{x:Type local:CustomControl1}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type local:CustomControl1}"> 
       <Border Background="{TemplateBinding Background}" 
         BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}"> 

        <ContentControl Template="{DynamicResource myControlTemplate1}"></ContentControl> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

generic.xaml을에서 나는 다음과 같은 코드가 있습니다. 왜 ?

그러나 템플릿을 StaticResource으로 변경하면 작동합니다. 왜 ?

+0

가능한 복제 [WPF StaticResource works, DynamicResource 않습니다] (http://stackoverflow.com/questions/3537107/wpf-staticresource-works-dynamicresource-doesnt) – fahadash

답변

0

나는 대답은 (아래의 텍스트에서 마지막 문장) here에 생각 :

정적 자원 조회 시스템 자원에 테마로 확장, 또는 수 있지만, XAML 로더가를 연기 때문에에만 지원됩니다 의뢰. 지연은 페이지가로드 될 때의 런타임 테마가 응용 프로그램에 올바르게 적용되도록 필요합니다. 그러나 테마 또는 시스템 자원으로 만 존재하는 것으로 알려진 키에 대한 정적 자원 참조는 권장되지 않습니다. 이는 주제가 실시간으로 사용자에 의해 변경되는 경우 그러한 참조가 재평가되지 않기 때문입니다. 동적 리소스 참조는 테마 또는 시스템 리소스를 요청할 때보다 안정적입니다. 예외는 테마 요소 자체가 다른 자원을 요청할 때입니다. 앞에서 언급 한 이유로 이러한 참조는 정적 리소스 참조 여야합니다.

응용 프로그램 자원에 Generic.xaml을 병합 할 수 있지만 리소스 조회가 테마로 확장되지 않습니다.