이 예제를 사용하려고합니다. 나는 새로운 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
으로 변경하면 작동합니다. 왜 ?
가능한 복제 [WPF StaticResource works, DynamicResource 않습니다] (http://stackoverflow.com/questions/3537107/wpf-staticresource-works-dynamicresource-doesnt) – fahadash