Multibinding generates “Cannot set MultiBinding because MultiValueConverter must be specified”

后端 未结 3 396
一个人的身影
一个人的身影 2021-01-18 03:41

I have a button with binding which works fine, see below:

相关标签:
3条回答
  • 2021-01-18 04:13

    I know this thread is old, but I've faced the same problem yesterday where everything was written correctly yet the WPF was still refusing to locate the converter. What helped me was assigning the converter in the following manner:

    <MultiBinding Converter="{local:ButtonParametersMultiValueConverter}">
    

    That solved the issue.

    0 讨论(0)
  • 2021-01-18 04:27

    you have to implement IMultiConverter

    public class SearchFilterConverter : IMultiValueConverter
    {
     public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
     {
        return new Tuple<String, bool>((String)values[0], (bool)values[1]);;
     }
     public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    then create the resource in xaml

     <Converter:SearchFilterConverter x:Key="searchFilterConverter" />
    

    then it should work

    <Button x:Name="licenceFilterSet" Content="Search" Command="{Binding licenseSearchCommand}">
    <Button.CommandParameter>
        <MultiBinding Converter="{StaticResource searchFilterConverter}">
            <Binding Path="Text" ElementName="licenseTextBox" />
            <Binding Path="IsEnabled" ElementName="regularExpressionCheckBox" />
        </MultiBinding>
    </Button.CommandParameter>
    </Button>
    
    0 讨论(0)
  • 2021-01-18 04:29

    That is not the correct implementation of the IMultiValueConverter interface.

    The correct one is:

    public class SearchFilterConverter : IMultiValueConverter
    {
       public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
       {
          ....
       }
    
       public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
       {
       }
    }
    

    Reference here.

    0 讨论(0)
提交回复
热议问题