A Solution to Binding on Silverlight Behaviors

I posted a while ago about when first playing with Silverlight 3 Behaviors that you can't data bind to them. The reason being is that the base classes for Behaviors, Triggers and Actions are DependencyObject which Silverlight (but not WPF apparently) doesn't support data binding.

While talking with some of the Silverlight and Blend teams I've found while this is a known issue it won't be addressed in the Silverlight 3 timeframe. From what I gather rather than changing Behaviours to inherit from FrameworkElement we may see the data binding mechanisms changed to match with WPF.

There is an excellent post by Pete Blois "DataTrigger, Bindings on non-FrameworkElements, TypeConverters, DataStateBehavior & DataStateSwitchBehavior" which shows how you can get bindings on non FrameworkElements in Silverlight. To quickly sum up the solution involves exposing the properties as Binding objects rather than type you'd like to expose (and a lot of trickery involving attached dependency properties).

While this solution works (I've been using it to create an ExecuteCommandAction that I can bind Commands from my ViewModel) there is a major problem with this approach.

Simply put you have to make a decision when creating your Behavior do you want it to be bindable or to use values from the designer. Which means you need to create duplicate behaviours to get both sorts of functionality.