Live Chat Icon For mobile
Live Chat Icon

How can I restrict the use of style for certain types of controls ?

Platform: WPF| Category: Styles and Templates

If you want to enforce that a style can be applied to a particular type only, you can set its ‘TargetType’ property.

For example, the following style can only be applied to a button (or a subclass of a button).

[XAML]

<Style x: key='buttonStyle' TargetType='{x:Type Button}'>
	<Setter Property=' Button.FontSize' Value='22'/>
	<Setter Property=' Button.Background' Value='Purple'/>
	<Setter Property=' Button.Foreground' Value='While'/>
	<Setter Property=' Button.Height' Value='50'/>
	<Setter Property=' Button.Width' Value='50'/>
	<Setter Property=' Button.RenderTransFormOriginal' Value='.5,.5'/>
	<Setter Property=' Button.RenderTransForm'/>
	<Setter.Value >
		<RotateTransform Angle='10'/>
	</Setter.Value>
	</Setter>
</Style>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.