attachedbindings for silverlight 5

Posted by Karim on September 22, 2008

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.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Neil Mosafi Tue, 23 Sep 2008 02:58:30 UTC

    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. Josh Tue, 23 Sep 2008 20:32:13 UTC

    Nicely done Karim!

  3. [...] office show and tell every now and then I never got a chance to really look at this until now. http://dragonshed.wordpress.com/2008/09/22/attachedbindings-for-silverlight/ Categorized as [...]

  4. Mahesh Wed, 05 Nov 2008 14:13:13 UTC

    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

  5. Karim Wed, 05 Nov 2008 22:51:54 UTC

    @ 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.

Comments