0

The Converter property in the code from the blog post, Silverlight MultiBinding solution for Silverlight 4, is not a dependency property, so I can't bind it with a converter (that for technical reasons must be instantiated as part of Unity injection earlier in the application rather than as a simple static resource as part of a user control).

How can I modify the MultiBinding code to accept a bound converter? I tried to make it a dependency property:

public IMultiValueConverter Converter { get { return (IMultiValueConverter)GetValue(ConverterProperty); } set { SetValue(ConverterProperty, value); } }
public static DependencyProperty ConverterProperty = DependencyProperty.Register("Converter", typeof(IMultiValueConverter), typeof(IMultiValueConverter), null);

but I got

DependencyProperty System.Windows.Data.IMultiValueConverter. Converter cannot be set on an object of type ...Binding.MultiBinding.

If this is not a viable option, how can I bind the ConverterParameter property or get something to simulate bindings of a converter to a MultiBinding?

Kit
  • 20,354
  • 4
  • 60
  • 103
  • why not bind your data to the MultiBinding too? then you have the data in the multi value converter and your converter also fires if your data changes. – punker76 Dec 06 '11 at 21:06
  • @punker76, I'm not sure I follow you. I have, for example, 3 properties of a view model multi-bound, but they have to run through a converter to format properly in the view. The converter itself can't (so far as I know) be a static resource because *it* has dependencies injected into its constructor. – Kit Dec 06 '11 at 21:11
  • Mh, I have unfortunately not yet understood why you want to bind a converter? – punker76 Dec 06 '11 at 21:23
  • @punker76, because it is sufficiently complex to create that it's not convenient to make a static resource. The converter uses services to lookup information so that the end-result displayed "looks right" when formatted. – Kit Dec 06 '11 at 21:25

1 Answers1

0

I solved this using the "simulated bindings" route, though that's not my preference if someone has another answer. What I did instead was not build up the converter via dependency injection, but instead had it use service location to get it's needed dependencies. Generally I prefer dependency injection to service location. The "service location" was a matter of storing the Unity container in the application's global resources; from there it's not difficult to get what I need.

Kit
  • 20,354
  • 4
  • 60
  • 103
  • I don't have this luxury yet, but here's an SL5 solution for anyone who's interested: http://www.codeproject.com/KB/silverlight/SilverlightMultiBinding.aspx?display=Mobile – Kit Dec 06 '11 at 23:42