【发布时间】:2014-10-29 03:59:31
【问题描述】:
我正在尝试让这个示例正常工作。我创建了一个新的 WPF 自定义控件库项目,在 Generic.xaml 中我有以下代码
<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>
当我在应用程序中使用我的控件时,我看不到TextBlock。为什么?
但如果我将其更改为使用StaticResource 的模板,它就可以工作。为什么?
【问题讨论】:
标签: wpf wpf-controls