无法将类型 'MultiBinding' 的实例添加到类型 'DoubleCollection' 的集合中

Cannot add instance of type 'MultiBinding' to a collection of type 'DoubleCollection'

错误: 我正在尝试使用我编写的 IMultiValueConverter,但 Intellisense 给我这个错误 "Cannot add instance of type 'MultiBinding' to a collection of type 'DoubleCollection'. Only items of type 'double' are allowed."

问:我不明白这个错误是什么意思。我已经使用其他转换器修改其他路径中的 StrokeDashArray 属性;但是,我不确定如何使用多重绑定。有人可以解释为什么我会收到此错误,以及如何删除此错误吗?

详细信息: 转换器名为 "DashedWhenValue1ArrayEqualsValue2ArrayConverter",我在上面将其定义为 StaticResource。这是我的转换器中有趣的部分

. . . 
public DoubleCollection DoubleCollectionWhenEqual { get; set; }
public DoubleCollection DoubleCollectionWhenNotEqual { get; set; }
public DoubleCollection DoubleCollectionWhenValueIsNull { get; set; }

. . .

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{

  if (values == null || values.Length < 2)
  {
    return this.DoubleCollectionWhenValueIsNull;
  }

  if ( !(values[0] is Array) || !(values[1] is Array) )
  {
    return this.DoubleCollectionWhenNotEqual;
  }

  object[] array1 = values[0] as object[];
  object[] array2 = values[1] as object[];

  if (array1.Length != array2.Length)
  {
    return this.DoubleCollectionWhenNotEqual;
  }

  for (int i = 0; i < array1.Length; i++)
  {
    if (array1[i] != array2[i])
    {
      return this.DoubleCollectionWhenNotEqual;
    }
  }

  return this.DoubleCollectionWhenEqual;

}
. . .

我在这里的视图中使用我的转换器

<Path x:Name="some_Path" Data="M7,4.167 L7,162.08887" HorizontalAlignment="Right" Margin="0,0,-391.5,-871" StrokeStartLineCap="Square" StrokeEndLineCap="Square" Stroke="#FF33CC33" StrokeThickness="10" Width="10.5" RenderTransformOrigin="0,0" Height="167.167" VerticalAlignment="Bottom" >
      <Path.StrokeDashArray>
        <MultiBinding Converter="{StaticResource DashedWhenValue1ArrayEqualsValue2ArrayConverter}"> <!-- Error starts here -->
          <Binding Path="ModelViewProperty1" />
          <Binding Path="ModelViewProperty2" />
        </MultiBinding> <!-- Error ends here -->
      </Path.StrokeDashArray>
    </Path>

我能够在 Visual Studio 2015 中重现您的错误。这似乎只是 XAML 编辑器的错误,而不是您的 XAML 或转换器的实际问题.当我 运行 应用程序时,根据 ModelViewProperty1ModelViewProperty2 是否都具有值并且是否等价,我会得到不同的破折号。

因此,我的建议是忽略此特定错误。

P.S。只是为了好玩,这是使用 LINQ 编写 Convert 方法的更简洁的方法:

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
    var arrays = values
        .OfType<Array>()
        .Select(x => x.OfType<object>())
        .ToList();
    if (arrays.Count != 2) return DoubleCollectionWhenValueIsNull;
    return arrays[0].SequenceEqual(arrays[1]) ? DoubleCollectionWhenEqual : DoubleCollectionWhenNotEqual;
}