Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AdornerLayer for Path
Message
From
20/04/2010 14:02:20
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01460940
Message ID:
01461174
Views:
41
>>it does use ArrangeOverride BTW

I was looking for it in the window not the adorner, I see it now. < rolls eyes at self >

Very quick and dirty, I created a simple class that held the thumbs for the segment and the segment.

I then created a collection of that class in the adorner and walked it in arrange. Seems to work.

Not complete, but I think you'll get the picture.

here's what I came up with:
public class ThumbPoints
    {
    public Thumb Thumb1;
    public Thumb Thumb2;
    public Thumb Thumb3;
    public PathSegment Segment;
    }

  public class PathAdorner : Adorner
    {
    List<ThumbPoints> ThumbPoints;
    VisualCollection visualChildren;

    public PathAdorner(UIElement adornedElement) : base(adornedElement)
      {
      visualChildren = new VisualCollection(this);
      ThumbPoints = new List<ThumbPoints>();
      PathGeometry g = (PathGeometry)((Path)adornedElement).Data;
      foreach (PathFigure item in g.Figures)
        {
        foreach (PathSegment seg in item.Segments)
          {
          if (seg is LineSegment)
            {
            ThumbPoints pseg = new ThumbPoints();
            pseg.Segment = seg;
            BuildAdornerPoint(ref pseg.Thumb1, Cursors.Hand);
            ThumbPoints.Add(pseg);
            }
          else if (seg is BezierSegment)
            {
            ThumbPoints pseg = new ThumbPoints();
            pseg.Segment = seg;
            BuildAdornerPoint(ref pseg.Thumb1, Cursors.Hand);
            ThumbPoints.Add(pseg);
            }
          }
        }
      }
 
    protected override Size ArrangeOverride(Size finalSize)
      {
      foreach (ThumbPoints item in ThumbPoints)
        {
        if (item.Segment is LineSegment)
          {
          LineSegment line = (LineSegment)item.Segment;
          item.Thumb1.Arrange(new Rect(line.Point.X - 5, line.Point.Y - 5,10,10));
          }
        else if (item.Segment is BezierSegment)
          {
          BezierSegment line = (BezierSegment)item.Segment;
          item.Thumb1.Arrange(new Rect(line.Point3.X - 5, line.Point3.Y - 5, 10, 10));
          }
        }
      return finalSize;
      }

    void BuildAdornerPoint(ref Thumb pointThumb, Cursor customizedCursor)
      {
      if (pointThumb != null) return;
      pointThumb = new Thumb();
      pointThumb.Cursor = customizedCursor;
      pointThumb.Height = pointThumb.Width = 10;
      pointThumb.Opacity = 0.40;
      pointThumb.Background = new SolidColorBrush(Colors.MediumBlue);
      visualChildren.Add(pointThumb);
      }

    // Override the VisualChildrenCount and GetVisualChild properties to interface with 
    // the adorner's visual collection.
    protected override int VisualChildrenCount { get { return visualChildren.Count; } }
    protected override Visual GetVisualChild(int index) { return visualChildren[index]; }
    }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform