Tuesday, July 14, 2009

Silverlight Styling

Changing the styling of the Silverlight controls is simple. It’s somewhat similar to CSS, but it's more robust and syntax is completely different. What is different in Silverlight and WPF is that you can completely re-define control’s UI and behavior using styles. It took me about 20 minutes from absolute zero to the “Aha!” moment and become an expert in styling WPF and Silverlight applications. Here are the 3 links that helped me to clear the mistery behind Silverlight styles:


1.       Using Style Elements to Better Encapsulate Look and Feel – a good example of how to change control’s properties using styles


2.       Using Control Templates to Customize a Control's Look and Feel – a step further that shows how to make control look anyway you want. In other words how to draw control’s UI from scratch or combine several controls into one. All using styles! Pretty amazing yet simple.


3.       MSDN: Customizing the Appearance of an Existing Control by Using a ControlTemplate – the final piece of puzzle is about how to make control to react on events like Pressed or Disabled and change its appearance. Just few more words about this. Basically every control has a list of pre-defined events (they called states in Silverlight) which can be referenced by ControlTemplate. The list of states differs for each control. This information is available in MSDN on control’s Class page as a list of TemplateVisualStateAttribute attributes applied to the class.


-=Oleg=-

No comments:

Post a Comment