Jiew Meng
Jiew Meng

Reputation: 88187

Using Style for ComboBox and TextBox

Is there a way I can reuse Styles for more than 1 TargetType eg. ComboBox and TextBox

<Style TargetType="ComboBox, TextBox" />

is there such a thing? Or is the only way duplicate the style and target each style to differnt types?

Upvotes: 0

Views: 929

Answers (2)

Kirill Lykov
Kirill Lykov

Reputation: 1313

You can't (if I'm not mistaken). But what you may do in order to avoid copy-paste is to create a BaseStyle with a key and then create two styles for ComboBox and TextBox which are BasedOn the BaseStyle. smth like that:

<Style x:Key="BaseStyle" TargetType="{x:Type Control}">
   <Setter ... />
</Style>

<Style BasedOn="{StaticResource BaseStyle }" TargetType="{x:Type ComboBox }" />
<Style BasedOn="{StaticResource BaseStyle }" TargetType="{x:Type TextBox}" />

Upvotes: 3

Fatema
Fatema

Reputation: 135

Instead of this you can provide targettype as control and define setter proeprties of control and apply that style to textbox and combox.

Upvotes: 0

Related Questions