Binding on Style Setter in Silverlight 5

Continuing to our discussion on Silverlight 5 features. In earlier post, we discussed about Text Advancement in Silverlight 5. In this post, we will discuss on another new feature called Binding on Style Setter. This feature is very useful for the XAML designer. If you are a XAML designer, you must be aware of this cool new feature.


Read the complete post where we will discuss how we can bind to a Style Setter.



As you already know that, it is a new feature in Silverlight 5 and hence was not available in earlier version of Silverlight. So, how did we implement the style setter in previous versions? Let's start from the scratch, where we will know how to use a Setter in Style and then we will jump to the Setter binding.


Earlier to Silverlight 5 Beta, we were actually coded value to the Setter property like this:




We also had the option to use a StaticResource directly to the Setter property value, where StaticResource has been defined in the Resources. Have a look into the below code:




So, what about Binding? Binding to the setter is a new feature in Silverlight 5. By using this feature, you can actually bind to a control property or a StaticResource like this:




More preferred example for this feature will be this:




Here, we have our ViewModel defined as a StaticResource in our XAML page. Now we can directly bind the Collection defined in the ViewModel and set it in the Style Setter instead of declaring it in the control level. Here "Path" defines the collection present in our ViewModel.


Hope, this post helped you to understand the feature and it's uses. Stay tuned for my other posts on Silverlight 5 features.

If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly.

Don't forget to share your feedback/queries in the comment section below.


  1. Nice feature and great explanation. It will improve the design and development of the UI.

  2. Kunal - really nice to read your posts through-out the blog. Keep it up!

  3. Thanks Ravi and Gaurav. It's my pleasure to write more for you. Please don't forget to leave your feedback as this cheers me up to serve you better.

  4. thanks for sharing. it's an awesome feature.

  5. Hi Kunal,

    Explanation is very nice.

    I have downloaded and test the code. Its perfectly working for Button style setter but not for Listbox. I tried to debug the binding; MyCollection is null; I have assigned the collection of Person to MyCollection.

  6. Can you post the code snippet? Otherwise it is very difficult to analyse the problem. If possible share the sample project as ZIP.

  7. I rarely post comments but can't resist to say that your posts are very valuable and well presented.

  8. hi
    i have pciture and it is set to bg of button and when clicking the button it goes to white without showing image ?i want to image as it is when clicked and also some bg color changed to required color how can i do this


© 2008-2018 Kunal-Chowdhury.com | Designed by Kunal Chowdhury
Back to top