Define a convention to add custom converter based on control type and tag property value

Topics: Conventions
Jan 7, 2014 at 2:13 PM
Edited Jan 8, 2014 at 7:50 AM
I want to customize my caliburn conventions to handles a custom control called BaseText.
If one of controls in use that derive from BaseText has the Tag property in xaml set equals to custom converter name, I want to attach this converter to binding.

I have tried as show above:
            ConventionManager.AddElementConvention<BaseText>(BaseText.EditValueProperty, "Text", "EditValueChanged")
              .ApplyBinding = (viewModelType, path, property, element, convention) =>
                  var bindableProperty = convention.GetBindableProperty(element);
                  if (!ConventionManager.SetBindingWithoutBindingOrValueOverwrite(viewModelType, path, property, element, convention, bindableProperty))
                      return false;

                  if ((string)element.Tag == "DateTimeToTimeSpanConverter")
                      Binding binding = BindingOperations
                          .GetBindingExpression(element as DependencyObject, bindableProperty)

                      binding.Converter = customConv;
                  return true;
but statement
 binding.Converter = customConv
raise an error. Where is my mistake?

I can achieve my goal with a custom attribute on view-model, but I prefer to do this via ConventionManager.AddElementConvention. It's possible?
Thanks in advance.