Happy stress free coding

Apr 15, 2009

WPF Binding

It seems that I keep forgetting the reasons for why I created the EcoBinding as I did so I better write it down:

The issues with providing an alternative Binding class is mainly:

  1. The ProvideValue method is sealed in BindingBase so you cannot override it
  2. This forces you back to subclass MarkupExtension instead
  3. Stuff like templates and HierarchicalDataTemplate.ItemsSource requires a "BindingBase" and not a MarkupExtension, so you are smoked on those.

What if you created a MarkupExtension that provides the source to the existing binding then? Like this:

<SomeTarget Items={Binding Source={eco:OCL Expression=Class1.Allinstances}}/>

The problem with this approach is that the Binding class does not reveal its target (it holds it as a private weak reference), so the OCL-markupextension cannot get to the targets datacontext – and we really need that to create relative expressions.

What about a Converter then?

<SomeTarget Items={Binding Converter={eco:OCL Expression=Class1.Allinstances}}/>

This way we can let the OCL-markupextension return an IValueConverter. The problem here is that IValueConversion is totally linear; the result of the conversion should change if the result of the subscribed expression changes, but we have no way to make this happen since the binding only listens to the Source.

What about the Path then?

<SomeTarget Items={Binding Path={eco:OCL Expression=Class1.Allinstances}}/>

Path wants a PropertyPath class that is sealed.

 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home