Laden...

Custom Shape wird nicht nicht außerhalb gezeichnet, trotz ClipToBounds="False"

Letzter Beitrag vor 7 Jahren 1 Posts 1.065 Views
Custom Shape wird nicht nicht außerhalb gezeichnet, trotz ClipToBounds="False"

Hallo!

Ich habe eine art Legende, also ein Kästchen mit einem Pfeil, als custom shape erstellt, wobei der Pfeil außerhalb der Bounds des shapes gezeichnet werden soll. Hier der Code:


public sealed class Legend : Shape
  {
    public static readonly DependencyProperty ArrowLocationProperty = DependencyProperty.Register("ArrowLocation", typeof(Point), typeof(Legend), new FrameworkPropertyMetadata(new Point(-50, -50), FrameworkPropertyMetadataOptions.AffectsRender));

    [TypeConverter(typeof(PointConverter))]
    public Point ArrowLocation
    {
      get { return (Point)base.GetValue(ArrowLocationProperty); }
      set { base.SetValue(ArrowLocationProperty, value); }
    }

    protected override Geometry DefiningGeometry
    {
      get
      {
        var r = new RectangleGeometry(new Rect(0, 0, Width, Height));

        PathGeometry p = new PathGeometry();
        p.Figures.Add(
          new PathFigure(
            new Point(20, 0),
            new List<PathSegment> { new LineSegment(ArrowLocation, true), new LineSegment(new Point(0, 20), true) },
            true
          )
        );

        CombinedGeometry cg = new CombinedGeometry(GeometryCombineMode.Union, p, r);
        return cg;
      }
    }
  }

Ich benutze die Legende in einem Canvas:


<Window x:Class="LegendTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:LegendTest"
        mc:Ignorable="d" WindowStartupLocation="Manual" WindowStyle="None" AllowsTransparency="True"
        Title="MainWindow" Height="350" Width="525" Background="{x:Null}">
  <Grid>
    <Canvas x:Name="MainCanvas"  ClipToBounds="False" Background="white">
      <local:Legend x:Name="legend" Fill="Aquamarine" ArrowLocation="-50 -50" Width="100" Height="100" ClipToBounds="False" Canvas.Left="200" Canvas.Top="100" />
      <local:Legend x:Name="legend2" Fill="Aquamarine" ArrowLocation="-50 -50" StrokeThickness="1" Stroke="Black" Width="100" Height="100" ClipToBounds="False" Canvas.Left="50" Canvas.Top="100" />
    </Canvas>
  </Grid>
</Window>

Das Ergebnis ist im Angang dargestellt: Die Legende ohne Rahmen wird richtig dargestellt. Die Legende mit Rahmen nicht (Pfeil fehlt). Im Designer werden beide Shapes korrekt dargestellt. Ich habe leider keine Ahnung was da schief läuft.