【发布时间】:2009-08-21 14:33:04
【问题描述】:
我不熟悉使用ControlTemplate。我正在编写我的第一个控件,但我遇到了(在我看来)一个非常奇怪的问题。
我使TemplateBinding 工作的任何依赖属性,但来自 .NET 框架对象的任何属性,即ContentControl 的Content 属性或ItemsControl 的Items 属性不会被填充在运行时。
我确定我错过了什么……我不知道是什么……
代码示例如下:
目前这个类很简单:
public class Title : ContentControl
{
}
模板是:
<Style TargetType="{x:Type UI:Title}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type UI:Title}">
<TextBlock Text="{TemplateBinding Content}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
ContentControl 基类是位于 System.Windows.Controls.Control 命名空间中的 .NET 类。
谢谢,
亚当
【问题讨论】:
-
你能添加一个代码 sn-p 来显示什么不起作用吗?
-
很抱歉。我现在加了一个。谢谢。
标签: wpf controltemplate templatebinding