One more platform difference more-or-less tamed [SetterValueBindingHelper makes Silverlight Setters better!]

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of

See you there!

Comments (21)
  1. says:

    In WPF you can use the BindingOperations class to set a binding on a DependencyObject and then you don’t need to use FrameworkElement.

    FrameworkElement.SetBinding calls the method on BindingOperations.

  2. Thank you for submitting this cool story – Trackback from DotNetShoutout

  3. klinger says:

    Works great.

    I used it to attach commands (Silverlight prism v2) to items of our app menu:

    For each item in the menu I now use:

    <Button Text="Home" Tag="Destination#Permission" Style="{StaticResource ButtonNavigationCommandStyle}"/>                

    Instead of:          

    <Button Text="Home" Tag="Destination#Permission" Commands:Click.Command="{Binding NavigateCommand}" Commands:Click.CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Tag}"/>

    Very nice.

    Thanks for sharing.


  4. David Anson says:


    That’s great to hear! Thanks for sharing your success story. 🙂

  5. David Kelley says:

    A great little Hack in Silverlight, kind of technical stuff for the beginner but a good thing to have

  6. David Kelley says:

    A great little Hack in Silverlight, kind of technical stuff for the beginner but a good thing to have

  7. cosmin_nasoi says:


    I tried your solution for binding the Background property of a DataGridRow in Silverlight 3, using a style for datagrid’s RowStyle.

    <Setter Property="local:SetterValueBindingHelper.PropertyBinding">


                           <local:SetterValueBindingHelper Type="DataGridRow" Property="Background" Binding="{Binding Color}" />



    At some point I change the Color property of the datacontext object, make NotifyPropertyChanged("Color"), but the background of the specific row doesn’t change.

    How can I force the custom setter to rebind the Color property?…this meaning to be able to call SetPropertyBinding. I can’t obtain the DataGridRow from the business object and I’m stuck.

    Thanks in advance for helping.

  8. David Anson says:


    From the sound of it, I’d guess that either the Binding isn’t getting hooked up in the first place or else the notification by the data item isn’t coming through correctly. You could set some breakpoints in the SetterValueBindingHelper code to try to see which of these it might be. You might also see if this problem is present with a control other than DataGrid – it’s possible that the virtualization that control implements is getting in the way here. At any rate, I find the act of creating a clean, simplified demonstration of a problem is often helpful in understanding what’s going on – and a lot easier to debug, too. 🙂

    Hope this helps!

  9. cosmin_nasoi says:

    No, the binding is fine, ’cause I’ve been refreshing the datagrid items and the background is fine. The only bad thing is that I’m making datagrid.ItemsSource = null; datagrid.ItemsSource = _obsColl.

    I’m trying to add the setter into DataGridRowHeaderStyle, but didn’t succeed by now. I’m not sure if it’s possible to set the Type=<datagrid row header assembly> or somehow get access to the Background property of row’s Header.

    Thanks anyway for the control here…it is useful in many other places.

  10. David Anson says:


    Sorry for the difficulty! If you’re able to put together a simplified demonstration project you can share out, I may be able to have a look in the next few days.


  11. AlexeyYumashin says:

    Thank you for a great article!

    Is it possible to use some similar approach to fill the vacuumn with Triggers and Commands in Silverlight?! and with ability to bind to a property of another control as well?

  12. David Anson says:


    I don’t have any great ideas yet, but if I think of something, I’ll be sure to post about it! 🙂

  13. Andrew Smith says:

    This is a nice approach but it would seem to result in several issues. First, you get an incorrect valuesource for the value – i.e. this becomes a local value even though the setter may have been a theme or local style setter. Second, since you are setting a local value you would step on any local value that might have been set (e.g. use this in the theme style and set a local value on the element instance). Third, if this was done in an implicit/local style and you change the implicit style to one that doesn't have a setter, the value from the old setter would still be there (i.e. the binding remains in place). This is at least partially because you are not cleaning up the last DP that you targetted which I think you purposefully do to allow this single attached property to create bindings for multiple properties. Any idea on why this isn't supported in SL and when it will be?

  14. David Anson says:

    Andrew Smith,

    I don't disagree with anything you've said. 🙂 SetterValueBindingHelper was created to work around a limitation in the platform and while there may be ways I can make it a little closer to the WPF behavior it's trying to mimic, the very nature of the workaround means it's unlikely to ever be a completely seamless replacement. For my purposes – and that of others using SetterValueBindingHelper – the current implementation works quite well and the issues you raise (while legitimate) don't pose a problem in typical applications. If you have specific suggestions for how to improve SetterValueBindingHelper, I'd love to discuss them. And I share your eagerness to see this functionality supported by Silverlight itself as soon as possible. 🙂

  15. Greg says:


    Thanks for post, quite helpful. Only limitation I have, unless I'm not doing it correctly, is this can only be used once per dependancy object (since there is only one dependancy parameter – PropertyBinding). Is there a way I can do something like bind the FontFamily and FontSize for example on the same dependancy object? Other than creating PropertyBinding1, PropertyBinding2, …?


    <Setter Property="OstSilverlightCommonFramework:SetterValueBindingHelper.PropertyBinding">




                   Binding="{Binding FontSize}" />



    <Setter Property="OstSilverlightCommonFramework:SetterValueBindingHelper.PropertyBinding">




                   Binding="{Binding FontFamily}" />



  16. David Anson says:


    Thanks! I think you'll find that the "multiple properties" issue is easy with the latest release of the code:…/as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx

  17. James says:

    Doh… I see now that you use the Ms-PL.   Again thanks for a permissive license!

  18. winSharp93 says:

    Great solution!

    Just one thing:

    Could you please place a link to the new version (…/as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx) at the top of the posting (Ideally big text size and red :-D) saying that you should prefer using it?

    This would help people landing here through search engines (like me) who wonder why this code does not work under SL 4 anymore.

  19. David Anson says:


    Thank you for bringing this to my attention! I rarely edit posts after they've gone live, but this is a great example of something that *deserves* an edit. 🙂 I've removed the code from this post and added a link to the updated post/code as you suggest.

  20. MNIM says:

    What is the namespace for the local element of local:SetterValueBindingHelper?

  21. David Anson says:


    Per Page.xaml, it's: xmlns:local="clr-namespace:SetterValueBindingHelperDemo".

    But I think I updated the samples after writing this post, so in that same file you'll see: <delay:SetterValueBindingHelper …/>

    Which is: xmlns:delay="clr-namespace:Delay"

    Hope this helps!

Comments are closed.