Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

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

$
0
0
I want to custumize my caliburn conventions to handles a custom control that here we can call BaseText.
If one of controls in use that derive from BaseEdit 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)
                          .ParentBinding;

                      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.

Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>