views:

403

answers:

1

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 control template 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 control template 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 control template.

+3  A: 

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.

Aviad P.