我创建了一个自定义控件,但我无法将属性绑定到这样的内容:
<Style TargetType="control:Pie">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="control:Pie">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentControl Content="{Binding Path=Test}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
在我的控制之下
public string Test
{
get { return (string)GetValue(TestProperty); }
set { SetValue(TestProperty, value); }
}
public static readonly DependencyProperty TestProperty =
DependencyProperty.Register(
"Test",
typeof(string),
typeof(Pie),
new PropertyMetadata(null));
当我创建控件时,在 Test 属性中设置了一个字符串,但视图中没有出现任何内容...