【发布时间】:2013-05-01 15:03:51
【问题描述】:
我有一个自定义外观较少的控件。我创建了一个 Style 并在 style 中设置了依赖属性。
如何在模板中设置控件的背景。我可以在不显式声明依赖属性的情况下执行此操作吗?
public class AddressCustomControl:Control
{
static AddressCustomControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(AddressCustomControl), new ....)
}
// Few dependency properties here...
}
然后我在主题文件夹中的 Generic.xaml 中定义了布局,并指定了上述控件的目标类型。
数据绑定到控件的一切都很好。
我不希望在使用该控件时更改此控件的颜色以及字体和前景色等其他一些属性。
当我像这样在 xaml 中指定时,什么也没有发生:
<local:AddressCustomControl Address={Binding BillAddress} Background="Silver" /> // Background does not change when I do this.
我在这里缺少什么?可能我必须按照我的风格做一些事情吗?
这是我的风格:
<Style TargetType="{x:Type controls:AddressCustomControl}">
<Setter Property="Template">... setter value and the control template here... </Setter.Value> // May be I need to do something here that I am missing?
</Style>
感谢您的宝贵时间!
【问题讨论】:
标签: wpf