How do I apply a style to all elements of a particular type?
Often, you need to apply the same style to elements of a particular type, such as Button, TextBox, MenuItem, and so on. To do this, specify a style that uses the TargetType attribute. The following example demonstrates specifying Font settings and a Background color for all Buttons on a form:
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="FontFamily" Value="Times New Roman" />
<Setter Property="FontSize" Value="30" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Background" Value="#FFCA5132" />
</Style>
</Window.Resources>Note: For this to work properly, you must omit the Style's Key attribute!
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 10/23/10
Comment or report problem with topic
