attachedbindings for silverlight

Today I released a small pet project of mine on Codeplex, called AttachedBindings. It’s a library for Silverlight which attempts to bridge the feature gap of Bindings between Silverlight and WPF. It contains an attached behavior that implements a form of ElementName Binding between two FrameworkElements.

Here is a simple example, which shows a Calendar control that changes opacity when Slider.Value changes.

<e:Calendar ab:AttachedBinding.Binding=
    "TargetProperty=Opacity, ElementName=OpacitySlider, Path=Value"/>
<Slider x:Name="OpacitySlider" Minimum="0" Maximum="1"
    SmallChange="0.1" LargeChange="0.1" Value="1.0"/>

Enjoy!

Disclaimer : Thanks go to Neil Mosafi, his ElementNameBinder was first on the scene. I reasoned an Attached Behavior with a custom TypeConverter would be easier to use, and I was able to make some optimizations along the way.

5 Responses to “attachedbindings for silverlight”


  1. 1 Neil Mosafi September 23, 2008 at 2:58 am

    It’s nice, and great to see another solution for this! I’m sure they’ll be in Silverlight 2 when it’s finally released. I think I originally tried using an attached property, but then ended up making it an extra control cos I wanted better intellisense support for the various properties.

    Cheers
    Neil

  2. 2 Josh September 23, 2008 at 8:32 pm

    Nicely done Karim!

  3. 3 Mahesh November 5, 2008 at 2:13 pm

    I am trying to use attachedBinding in SL2 but XAML parser throws an exception.

    Scenario is simple, binding Slider value to TextBlock’s Text Property.
    Please advice.

    Thanks,
    Mahesh

  4. 4 dragonshed November 5, 2008 at 10:51 pm

    @ Mahesh,

    Without seeing the code and the exception, I can only guess at possible causes. Slider.Value and TextBlock.Text properties have different types, so you will need to use a Value Converter to bridge the two. An example of how to do this is in the Sample included, defined at the bottom of Page.xaml.cs, used by Page.xaml (lines 13 and 86). Hope that helps.


  1. 1 Karim’s attached bindings in Silverlight | designerslove.net Trackback on October 27, 2008 at 1:28 pm

Leave a Reply




 

September 2008
S M T W T F S
« Aug   Feb »
 123456
78910111213
14151617181920
21222324252627
282930  

about

Karim Hernandez is a dev at IdentityMine, building software using WPF and Silverlight.

profiles