1

Is it possible to use classical converter with parameters with QuickConverter MultiBinding in WPF ?

More clearly, I want to bind the Text property of a TextBlock to display a text like this :

<MyApplication> + ' v' + <1.0>

MyApplication comes from a string resource Resources.String225 and 1.0 might comes from an IValueConverter class type to which I may pass the parameter myParameter . I tried the XAML code below,

<TextBlock Text="{qc:MultiBinding '$V0 + \' v\' + $V1',
 V0={x:Static resx:Resources.String225},
 V1={Binding Converter={StaticResource ProgramVersionConverter}, ConverterParameter='myParameter'}}"/>

With the following Converter :

public class ProgramVersionConverter : IValueConverter
{
    public static Func<string, string> GetApplicationExeVersion;

    /// <summary>
    /// Returns version of the executable
    /// </summary>
    /// <param name="value"></param>
    /// <param name="targetType"></param>
    /// <param name="parameter"></param>
    /// <param name="culture"></param>
    /// <returns></returns>
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return GetApplicationExeVersion?.Invoke((string)parameter);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException("ProgramVersion converter ConvertBack not supported.");
    }
}

GetApplicationExeVersion is set to a method in another part of code, not needed there.

But I'm getting this Exception at runtime :

System.Windows.Markup.XamlParseException:
'Unable to set' Binding 'on property' V1 'of type' MultiBinding '.
A 'Binding' can only be defined on a DependencyProperty of a DependencyObject. '

Am I in the rigth way or it is not possible to do it ?

Thank you for your attention.

  • 1
    Check out the [How to bind multiple values to a single WPF TextBlock?](https://stackoverflow.com/questions/2552853/how-to-bind-multiple-values-to-a-single-wpf-textblock) – neelesh bodgal May 31 '20 at 05:03
  • 2
    Thank you, but @neelesh bodgal, I'm using the QuickConverter library https://github.com/JohannesMoersch/QuickConverter and I'd do it with this library. –  May 31 '20 at 09:49

1 Answers1

0

Of course, you can.
If you want to add a value as a result of a System.Windows.Data.Binding (or System.Windows.Data.MultiBinding etc.), you have to use one of the P0...P9 properties of the QuickConverter.MultiBinding, as they only accept binding expressions. The V0...V9 properties only accept constant values, no binding expressions.

<TextBlock Text="{qc:MultiBinding '$V0 + \' v\' + $P0',
 V0={x:Static resx:Resources.String225},
 P0={Binding Converter={StaticResource ProgramVersionConverter}, ConverterParameter='myParameter'}}"/>
BionicCode
  • 1
  • 4
  • 28
  • 44