I working on a WPF project where I've over-ridden the CheckBox
control for some special operations. That is working correctly.
My problem is that the ControlTemplate
that was applied from the theme (shinyred.xaml from codeplex), is not applied to my over-ridden control. Is there a way to inherit the CheckBox
ControlTemplate
for use by my new control?
All the samples the I can find are focused on inheriting the style for the CheckBox
, but nothing about the ControlTemplate
.
No, as you said it is possible to 'inherit' a style by using the BasedOn
property, but it's not possible to directly 'inherit' a template. This is understandable though, what would be the semantics of template inheritance? How would the derived template be able to somehow add or change elements in the base template?
With styles it's entirely possible, since you can simply add Setters
, Triggers
, etc. The only thing that would conceivably be possible with template inheritance is adding Triggers
to the base template. However, in that case you'd have to have intimate knowledge of the element names in the base template, and an element name change in the base template could break your derived one. Not to mention an issue with readability, where you refer to a name in your derived template, which is defined somewhere else entirely.
Belated Addition Having said all that, it is possible to resolve your particular problem (although I doubt by now it is still yours, or even a problem). You simply define a style for your control with a setter for the Template
property thus:
<Style TargetType="<your type>">
<Setter Property="Template" Value="{StaticResource <existing template resource name>}"/>
</Style>