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

偶尔善良 提交于 2019-12-01 17:55:48

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>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!