1

我花了几个小时仔细检查错误原因是什么,但我不知道..

错误是

PresentationFramework.dll 中出现“System.Windows.Markup.XamlParseException”类型的第一次机会异常

附加信息:“设置属性 'System.Windows.Data.MultiBinding.Converter' 引发异常。” 行号“363”和行位置“86”。

XAML

<Grid Margin="1"
      DockPanel.Dock="Top">
  <Canvas x:Name="MinimapGrid"
          LayoutUpdated="MinimapGrid_LayoutUpdated">
    <Canvas.Resources>
      <local:OverlayRectangleRegionConverter x:Key="OverlayRectangleRegionConverter" />
    </Canvas.Resources>
    <Canvas.Background>
      <VisualBrush>
        <VisualBrush.Visual>
          <ItemsControl x:Name="itemsControl"
                        ItemsSource="{Binding Wells, IsAsync=True}">
            <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                <UniformGrid Rows="{Binding Rows, FallbackValue=16}"
                             Columns="{Binding Columns, FallbackValue=24}" />
              </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
              <DataTemplate>
                <Rectangle Fill="{Binding Name, Converter={StaticResource WellTypeColorConverter}}"
                           Height="10"
                           Width="10"
                           Stroke="Black" />
              </DataTemplate>
            </ItemsControl.ItemTemplate>
          </ItemsControl>
        </VisualBrush.Visual>
      </VisualBrush>
    </Canvas.Background>
    <Image x:Name="image"
           Height="410"
           Width="592"
           Source="Desert.jpg"
           Stretch="UniformToFill" />
    <Rectangle Fill="#FD9D5C5C"
               Canvas.Left="0"
               Canvas.Top="0"
               Width="{Binding ActualWidth, ElementName=image}"
               Height="{Binding ActualHeight, ElementName=image}"
               x:Name="rect">
      <Rectangle.OpacityMask>
        <DrawingBrush Stretch="None">
          <DrawingBrush.Drawing>
            <GeometryDrawing Brush="#99ffffff">
              <GeometryDrawing.Geometry>
                <CombinedGeometry GeometryCombineMode="Exclude">
                  <CombinedGeometry.Geometry1>
                    <RectangleGeometry>
                      <RectangleGeometry.Rect>
                        <MultiBinding Converter="{StaticResource OverlayRectangleRegionConverter}">
                          <Binding Path="(Canvas.Left)"
                                   ElementName="image" />
                          <Binding Path="(Canvas.Top)"
                                   ElementName="image" />
                          <Binding Path="Width"
                                   ElementName="rect" />
                          <Binding Path="Height"
                                   ElementName="rect" />
                        </MultiBinding>
                      </RectangleGeometry.Rect>
                    </RectangleGeometry>
                  </CombinedGeometry.Geometry1>
                  <CombinedGeometry.Geometry2>
                    <RectangleGeometry>
                      <RectangleGeometry.Rect>
                        <MultiBinding Converter="{StaticResource OverlayRectangleRegionConverter}">
                          <Binding Path="(Canvas.Left)"
                                   ElementName="PART_ZoomThumb" />
                          <Binding Path="(Canvas.Top)"
                                   ElementName="PART_ZoomThumb" />
                          <Binding Path="Width"
                                   ElementName="PART_ZoomThumb" />
                          <Binding Path="Height"
                                   ElementName="PART_ZoomThumb" />
                        </MultiBinding>
                      </RectangleGeometry.Rect>
                    </RectangleGeometry>
                  </CombinedGeometry.Geometry2>
                </CombinedGeometry>
              </GeometryDrawing.Geometry>
            </GeometryDrawing>
          </DrawingBrush.Drawing>
        </DrawingBrush>
      </Rectangle.OpacityMask>
    </Rectangle>
    <Thumb x:Name="PART_ZoomThumb"
           Canvas.Left="0"
           Canvas.Top="0"
           DragCompleted="PART_ZoomThumb_DragCompleted"
           DragDelta="PART_ZoomThumb_DragDelta"
           Cursor="SizeAll">
      <Thumb.Style>
        <Style TargetType="Thumb">
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="Thumb">
                <Rectangle StrokeThickness="3"
                           Stroke="Red"
                           Fill="Transparent" />
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </Thumb.Style>
    </Thumb>
  </Canvas>
</Grid>

OverlayRectangleRegionConverter.cs

public class OverlayRectangleRegionConverter : MarkupExtension, IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values == null || values.Length != 4) return new Rect(0, 0, 0, 0);
        for (var i = 0; i < values.Length; i++)
            if (double.IsNaN((double)values[i]))
                values[i] = 0.0;
        return new Rect((double)values[0], (double)values[1], (double)values[2], (double)values[3]);
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return new RectConverter();
    }
}
4

0 回答 0