【发布时间】:2010-07-02 10:08:20
【问题描述】:
我正在我的自定义控件类 DataPoint 中创建依赖属性:
public abstract class DataPoint : Control
{
public Color BaseColor
{
get { return (Color)GetValue(BaseColorProperty); }
set { SetValue(BaseColorProperty, value); }
}
public static readonly DependencyProperty BaseColorProperty =
DependencyProperty.Register("BaseColor", typeof(Color), typeof(DataPoint), new UIPropertyMetadata(Colors.DarkRed));
// Other class stuff
}
然后我创建其他自定义控件AreaDataPoint继承DataPoint:
public class AreaDataPoint : DataPoint
{
static AreaDataPoint()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(AreaDataPoint), new FrameworkPropertyMetadata(typeof(AreaDataPoint)));
}
// Other class stuff
}
在 xaml 中,我试图为 BaseColor 属性赋值,但它不起作用
<Style TargetType="{x:Type local1:AreaDataPoint}">
<Setter Property="BaseColor" Value="DarkGreen" />
</Style>
【问题讨论】:
-
“它不起作用”是什么意思。您能告诉我们错误消息、异常或错误结果等吗?
标签: c# wpf styles dependency-properties