I created an inline MultiBinding
using this post as a reference. More specifically, I'm using Christian Myksvoll's answer for creating a custom binding. My class looks like this:
public class MultiBinder : MultiBinding
{
public MultiBinder(BindingBase[] bindings, object converter)
{
foreach (BindingBase b in bindings)
{
Bindings.Add(b);
}
Converter = converter as IMultiValueConverter;
}
public MultiBinder(BindingBase b1, BindingBase b2, object converter)
{
Bindings.Add(b1);
Bindings.Add(b2);
Converter = converter as IMultiValueConverter;
}
public MultiBinder(BindingBase b1, BindingBase b2, BindingBase b3, object converter)
{
Bindings.Add(b1);
Bindings.Add(b2);
Bindings.Add(b3);
Converter = converter as IMultiValueConverter;
}
public MultiBinder(BindingBase b1, BindingBase b2, BindingBase b3, BindingBase b4, object converter)
{
Bindings.Add(b1);
Bindings.Add(b2);
Bindings.Add(b3);
Bindings.Add(b4);
Converter = converter as IMultiValueConverter;
}
}
I added the first array constructor just to see if I could make it handle an unknown number of bindings, but I couldn't get the call to work. So, I removed it, and now I'm trying to use the 3 value constructor :
<MyControl IsEnabled="{util:MultiBinder
{Binding Path=IsRequestedPriceControlEnabled},
{Binding Path=IsIndicative},
{StaticResource MultiBoolConverter}
}" />
It's giving me this error:
Cannot set MultiBinding because MultiValueConverter must be specified.
The converter I'm providing implements IMultiValueConverter
and is being used without problem in a style block elsewhere. I can't use it in a style block for this purpose due to the sheer number of control types and variable conditions required.
Class Declaration: public class MultiBoolToBoolConverter : IMultiValueConverter
Resource: <util:MultiBoolToBoolConverter x:Key="MultiBoolConverter" />
The only thing I can figure is that it doesn't recognize that the 3rd parameter is the converter. I've tried tinkering with the IsEnabled
content to explicitly set Converter
like Discord's example (along with trimming down the class to only have a single constructor with 2 parameters), but that didn't work, either. That gives this error:
Unknown property 'Converter' for type 'MS.Internal.Markup.MarkupExtensionParser+UnknownMarkupExtension' encountered while parsing a Markup Extension.
My Question:
Has anyone made an inline multi-binding like this and know what I'm doing wrong?
Note: I'm using .NET 4.6, so I can use any other functionality if needed.
EDIT:
I still get the "Cannot set [...]" error above in the designer even with Evk's defaulting to null and using a dummy converter. But, it does run. I'm testing it with this:
CommandParameter="{util:MultiBinder {Binding Path=IsExpiriesComboBoxEnabled}, {Binding Path=IsIndicative}, {StaticResource MultiBoolConverter}}"
If I put a breakpoint in the MultiBinder, it goes into the 3 parameter overload (b1,b2,converter) correctly, and I can see the Converter
being set to the MultiBoolConverter. So, I don't know why it's still giving the designer error.
SOLUTION:
The problem was a really, really stupid one. At some point after migrating the solution from VS2008 to VS2015, a XAML designer gave me an error or something and suggested disabling code execution, so I did. So, using the inline multibinder was confusing it since the converter wasn't being passed in. I had a hard time finding where to turn code execution back on, but once I did, it worked. So, the inline multibinding DOES work -- if it is being executed.
If you run into the same problem, here's the button that eluded me: