Monday, June 28, 2010

Stylesheets in WPF

As we create Stylesheets in HTML, Similarly we can create Styles in WPF application, which can be inherited by all the UI components in WPF based application.

 Changing the property of a control in Stylesheets will change that property across entire application, which is inheriting the stylesheets. As we have inline styles & cascading styles in html ,the same concept I found in WPF. If you define styles inline then they override the inherited property of styles. Here also we find that kind of parent child relationship.

Defining a Style.

Now the Question comes How to define Styles

Lets consider that you want common background on every window you create





Now lets create a window using that style


You don't need to mention background color on every window now. & changing the color at stylesheet level will reflect across every window which is inheriting this stylesheet.


Lets give some gradient effect & title to the Window


The same screen will now look like this.
Similarly you can set font size,font family for the entire application at single place & inherit across every where.You can set styles for all types of UI controls like labels,buttons, combo boxes etc

No comments:

Post a Comment