开发者

Setting converter value to null

开发者 https://www.devze.com 2023-04-04 05:26 出处:网络
I have a general function for binding with a converter parameter. When I don\'t need a converter I want to pass in null but it doesn\'t let me it says:

I have a general function for binding with a converter parameter. When I don't need a converter I want to pass in null but it doesn't let me it says:

Cannot set MultiBinding because MultiValueConverter must be specified.

Befor开发者_开发技巧e assigning it in the function i check if the converter was null, but I guess the issue is that IMultiValueConverter doesn't accept null as value.

Is there anyway to achieve this, without creating a Converter that just returns the input, or an overloaded method?

protected MultiBinding CreateBinding(object source, IMultiValueConverter converter, object parameter, object [] dps)
    {
        MultiBinding multiBinding = new MultiBinding();
        if ( converter != null )
        multiBinding.Converter = converter;
        multiBinding.ConverterParameter = parameter; 
        .....

In other words I want to simulate a direct property binding without a converter, using the function above.


MultiBindings only make sense if you specify a MultiValueConverter or a StringFormat to define how the output is calculated based on each source.

I'm not sure on what you're trying to achieve, but if you specify an empty StringFormat (string.Empty), you should get no errors, but it won't do anything at runtime.

0

精彩评论

暂无评论...
验证码 换一张
取 消