Monday, July 30, 2012

Common Themes in WPF

An interesting issue that might present itself to any WPF developer is that there is no apparent way to set a common style for a particular control or even for a form as a whole. At least, the method is there but the properties to use seem well hidden and don't really present themselves till you get to advanced sections of a good WPF book. Having obtained the solutions to these problems I thought it was only fair that I post out on the internet what I found.

For applying themes to a common control such as a button,

A quick look at the code will show how akin this is to the practice of CSS. There are styles that have a name, a target, and the property which they affect of those target controls. From that point on there are styles which are based on (inherit) the previously declared attributes that can be more applied in a more granular fashion. While this is pretty good, it turns out that if you want to change the font sizes and colours for an entire form, the solution is far simpler than this. 

Yessir. That's all you need. I would suggest playing more with the TextElement properties to see what else can be changed. Essentially, by setting this value you set the style for all controls that follow inside that. There are other elements to play around with but this is it in a nutshell. 

Happy coding!

No comments:

Post a Comment