1
我有一个自定义看起来更少的控制。我创建了一个Style并在样式中设置了依赖项属性。如何设置Lookless自定义控件背景?
如何在模板中设置控件的背景。我可以做到这一点,而不显式声明一个依赖属性?
public class AddressCustomControl:Control
{
static AddressCustomControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(AddressCustomControl), new ....)
}
// Few dependency properties here...
}
然后我在主题文件夹中的Generic.xaml中定义了布局,并指定了上述控件的targettype。
一切都很好,因为数据绑定到控制。
不是我想要的这个控件的颜色和像使用控件时改变字体和前颜色的其他一些属性。
当我在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>
感谢您的时间!
完美运作。感谢您的时间和链接。 – isakavis 2013-05-01 15:21:31