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