-2

We have an odd case where a Binding that's used as child of a MultiBinding needs its Converters Convert method to know the ultimate data type the MultiBinding is bound to.

For a regular Binding with a Converter, if it's bound to the Text property of a TextBlock, the Convert method will receive System.string in its targetType argument.

However if that same Binding is instead added as a child of a MultiBinding, even if that MultiBinding is assigned to a Text property itself, all child Binding's Converter's Convert methods will receive System.object as the targetType argument, not System.string. This kind of makes sense as technically their target is now the MultiBinding, not the Text property.

Still, I'm wondering if it can be set up so that information is passed through to the child Bindings. I'm thinking no, but I figured if anyone would know, it would be the S.O. community.

Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
  • You've seen this? https://stackoverflow.com/q/42784793/1136211 – Clemens Sep 06 '18 at 06:51
  • Yeah, I've seen that, but its conclusions don't apply here where we're controlling the MarkupExtension and thus the MultiBinding ourselves. I actually have a plan... grabbing the converter from the child binding and storing it in a variable, then removing it from that child binding, then manually calling it from within the converter on the multi binding where we're handed the now-unconverted value as one of the inputs. Then we simply pass the correct type through, additionally handling TargetNullValue as well. Testing now and will post as an answer if to works. – Mark A. Donohoe Sep 06 '18 at 17:05
  • Oh how I love down-votes for no good reason! I'm gonna suggest people who down-vote without explanation get banned from doing so, or at least make it a requirement they enter something. – Mark A. Donohoe Sep 06 '18 at 17:08
  • *"its conclusions don't apply here where we're controlling the MarkupExtension and thus the MultiBinding ourselves"* - there is no mention of that in the question, so how should anybody have taken that into account without having read your recent StackOverflow posts? Even with that knowledge it would have been hard to judge if that is actually what you're after. – Clemens Sep 06 '18 at 20:54
  • I didn't want to restrict my question to our specific use-case. You asked me had I seen that article, and I replied I did, but it didn't apply to my specific scenario, hence I asked the question myself slightly differently. That's all. Not trying to downplay your link. – Mark A. Donohoe Sep 06 '18 at 20:57

1 Answers1

1

Ok, so... the short answer is 'No, you can't!' However, the long answer is 'Yes you can, with a bit of work!'

The trick is instead of letting the child Binding handle the converter, you manually call it from the MultiBinding's own converter.

I've actually written a pretty long explanation of how all this works here on StackOverflow.com in the following answer:

How to create a DynamicResourceBinding.

Specifically, check out both the ProvideValue and the WrapperConvert functions. Lots of comments explaining what's going on and why.

Community
  • 1
  • 1
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286