views:

23

answers:

2

I am creating a custom WPF control class which inherits from ComboBox. As I am just defining behavior, the exiting ComboBox templates are fine for my purposes and I don't want to created a whole set of templates to support different themes. Is there a way to specify that my control uses the existing ComboBox templates?

+1  A: 

Give your control a default style and set BasedOn to the default style of ComboBox:

<Style TargetType="{x:Type local:CustomControl1}"
       BasedOn="{StaticResource {x:Type ComboBox}}">
</Style>

This will inherit the template setter from the ComboBox default style.

Quartermeister
Although Thomas's answer will also work for this situation and has its own advantages, using this method instead will allow you to later override the default Style for your custom control separately from the one for ComboBox without needing to go back and adjust the control's code.
John Bowen
+1  A: 

You don't have to do anything. If your control inherits from ComboBox and you don't override the DefaultStyleKey property, it will use the same style as ComboBox (thus the same template)

Thomas Levesque
I tried this at first but the defualt behviour of the wizard is to override the key and I got an invisible control. This is a good solution and it works so I've given it a vote but I've accepted the other one as the gives you the ability to selectively override and extend the existing template which is nice.
Shane