Kevin McNeish Blog

All things iOS, Kindle and .NET

Recent Posts

Tags

News

  • First books in my new book series, "iOS App Development for Non-Programmers" are now available! iBookStore: http://itunes.apple.com/us/book/book-1-diving-in-ios-app-development/id558788074?mt=11 Amazon: http://www.amazon.com/dp/B0097N8XBE Amazon: http://www.amazon.com/dp/B0099RQGMQ

Community

Email Notifications

Archives

How to apply a WPF 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!

Kevin McNeish
INETA Speaker

Microsoft .NET MVP
President, Oak Leaf Enterprises, Inc.
Chief Architect, MM .NET Application Framework
http://www.oakleafsd.com/

Comments

Don McNeish said:

Hello Kevin,

I came across your blog and noticed that we have the same last name. That doesn't happen too often with "McNeish". I'm on Facebook too at www.facebook.com/profile.php

Take care, Don

# June 15, 2009 11:39 AM
Leave a Comment

(required) 

(required) 

(optional)
 

(required) 

If you can't read this number refresh your screen
Enter the numbers above: