Reputation: 785
I have a custom look less control. I created a Style and set the dependency properties in the style.
How do I set the background of the control in the template. Can I do this without explicitly declaring a dependency property?
public class AddressCustomControl:Control
{
static AddressCustomControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(AddressCustomControl), new ....)
}
// Few dependency properties here...
}
Then I have the layout defined in Generic.xaml in the themes folder and specified targettype of the above control.
Everything is good as for data binding to the control.
Not I want the color of this control and few other properties like font, and fore color to be changed while using the control.
When I specify in the xaml like this nothing happens:
<local:AddressCustomControl Address={Binding BillAddress} Background="Silver" /> // Background does not change when I do this.
What am I missing here? May be I have to do something in my style?
This is my style:
<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>
Thanks for your time!
Upvotes: 1
Views: 109
Reputation: 9565
In the Generic.xaml file you should set something like this on the control
Background={TemplateBinding Background}
For additional info check out this link, under the section "preserving the functionality of a control's properites using templatebinding."
Upvotes: 1