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 dlaa.me.
See you there!
Comments
Anonymous
May 06, 2009
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.Anonymous
May 07, 2009
Thank you for submitting this cool story - Trackback from DotNetShoutoutAnonymous
May 09, 2009
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. KlingerAnonymous
May 10, 2009
Klinger, That's great to hear! Thanks for sharing your success story. :)Anonymous
June 04, 2009
The comment has been removedAnonymous
June 04, 2009
The comment has been removedAnonymous
January 25, 2010
Hi 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"> <Setter.Value> <local:SetterValueBindingHelper Type="DataGridRow" Property="Background" Binding="{Binding Color}" /> </Setter.Value> </Setter> 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.Anonymous
January 26, 2010
cosmin_nasoi, 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!Anonymous
January 26, 2010
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.Anonymous
January 27, 2010
cosmin_nasoi, 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. Thanks!Anonymous
March 26, 2010
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?Anonymous
March 27, 2010
AlexeyYumashin, I don't have any great ideas yet, but if I think of something, I'll be sure to post about it! :)Anonymous
June 04, 2010
The comment has been removedAnonymous
June 04, 2010
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. :)Anonymous
July 01, 2010
Delay, 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, ...? e.g.) <Setter Property="OstSilverlightCommonFramework:SetterValueBindingHelper.PropertyBinding"> <Setter.Value> <OstSilverlightCommonFramework:SetterValueBindingHelper Property="FontSize" Binding="{Binding FontSize}" /> </Setter.Value> </Setter> <Setter Property="OstSilverlightCommonFramework:SetterValueBindingHelper.PropertyBinding"> <Setter.Value> <OstSilverlightCommonFramework:SetterValueBindingHelper Property="FontFamily" Binding="{Binding FontFamily}" /> </Setter.Value> </Setter>Anonymous
July 01, 2010
Greg, Thanks! I think you'll find that the "multiple properties" issue is easy with the latest release of the code: blogs.msdn.com/.../as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspxAnonymous
August 05, 2010
Doh... I see now that you use the Ms-PL. Again thanks for a permissive license!Anonymous
October 29, 2010
Great solution! Just one thing: Could you please place a link to the new version (blogs.msdn.com/.../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.Anonymous
October 31, 2010
winSharp93, 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.Anonymous
May 31, 2013
What is the namespace for the local element of local:SetterValueBindingHelper?Anonymous
May 31, 2013
MNIM, 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!