Bookmark and Share Share...    Subscribe to this feed Feed   About Christian Moser  

Override the default Style in WPF

If you want to replace the default style of a control you can define a "typed style". A typed style only has an implicit key. The key is the Type object of the TargetType. All controls beneath the definition will inherit the style automatically.

<Style TargetType="Button">
  <Setter Property="FontWeight" Value="Bold" />

Last modified: 2008-10-29 21:09:56
Copyright (c) by Christian Moser, 2011.

 Comments on this article

Show all comments
Commented on 20.April 2009
Really good concept in WPF styles .. Extensive use of object oriented programmin
Commented on 1.June 2009
There is one property called "overridesDefaultStyle" through which we can override default style and set our own styish button right? can u tell us, how to do that
Commented on 5.August 2009
Ginkgo Biloba a herb that improves the flow of oxygen to the brain.;
Commented on 21.August 2009
Too bad the TargetType DependencyProperty wants a REAL type, not a string. Your TargetType SHOULD read: {x:Type Button} instead. I hope you're not actually on Microsoft payroll...
Rajesh Kumar...
Commented on 25.August 2009
Good article, It's help me a lot to learn. Keep it up
bob b.
Commented on 17.September 2009
I'm not sure what version of the .NET runtime tpartee's using, but the markup given above is perfectly valid, although it is still valid to use the more verbose {x:Type Button} markup as well.
Commented on 19.July 2010
Excellent article. This helped me a lot to learn WPF.
Commented on 15.September 2010
Commented on 4.November 2010
This is ridiculous. There is no separation of the presentation layer from the application layer by embedding styles in application code. This is why Microsoft is failing...they think everyone just wants to use their canned UI elements and nothing more. Styling elements is hit & miss in this technology. I have on multiple occasions created a template with a 1px border on the button and have had to go into other areas of the application code to change the border from 3px to 1px. This is ridiculous and I am glad to see Microsoft struggling to remain relevant. Silverlight / WPF are not good technologies to use if you wish to create FAST LOADING, SIMPLE User Interfaces.
Commented on 19.November 2010
Not sure where you are coming from amidude. There is actually a very good separation between presentation and application in WPF when you use the proper design patterns. As far as border sizes, is it not possible that there is an error in your code instead of Microsoft's?

E-Mail (optional)