I am trying to get this example working. I created a new WPF Custom Controls Library project and in Generic.xaml I have the following code
<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>
When I use my control in an application, I do not see the TextBlock
. Why ?
But if I change it to use the template as StaticResource
, it works. Why ?