开发者

Reusing existing templates in custom WPF controls

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 exis开发者_高级运维ting ComboBox templates?


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜