Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AdornerLayer for Path
Message
From
22/04/2010 04:34:45
 
 
To
21/04/2010 13:30:58
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01460940
Message ID:
01461435
Views:
45
>>What an Idiot!
>>My code was pretty much similar to yours (although I was only testing with one Path) but I had tried with (for example)
>>t1.Arrange(new Rect(bs.Point1, new Point(12, 12)));
>>//instead of
>>t1.Arrange(new Rect(bs.Point1.X, bs.Point1.Y, 12, 12));
Lord knows what I was expecting that constructor version to do :-{
>>Thank you...
>>BTW I don't think the '-5' offset if required in the ArrangeOverride in this instance - seems to centre correctly without it...
>>Viv
>>
>>>>>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]; }
>>>    }
>
>YW, I don't know about you but for me when I'm fighting with something it usually seems to be something stupidly simple when I find it. <g>
>
>I spent most of a day fighting with a web page last week. Turned out it was a badly formed set of if/endif tags for my pngfix.js. I could have screamed when I finally found it.

I think you're right - always the one's that look hard turn out to be simple. In my defence in this instance I hadn't really started to look for why it didn't work since I wasn't entirely sure that it *should* work :-}


>Translate transform trick in the other post is cool, I'll remember that when I get around to this on my todo list.
Previous
Reply
Map
View

Click here to load this message in the networking platform