Beispiel #1
0
        private void PlaceThumbs(PathGeometry pathGeometry)
        {
            foreach (PathFigure figure in pathGeometry.Figures)
            {
                {
                    MoveThumb thumb = new MoveThumb();
                    Canvas.SetLeft(thumb, figure.StartPoint.X);
                    Canvas.SetTop(thumb, figure.StartPoint.Y);
                    thumb.Style    = FindResource("thumbStyle") as Style;
                    thumb.Template = FindResource("thumbTemplate") as ControlTemplate;
                    canvas.Children.Add(thumb);
                    thumb.DragDelta += Thumb_DragDelta;
                    thumb.Tag        = new ThumbTag()
                    {
                        Figure       = figure,
                        IsStartPoint = true
                    };
                }
                List <MoveThumb> thumbs = new List <MoveThumb>();
                foreach (Point point in (figure.Segments[0] as PolyLineSegment).Points)
                {
                    MoveThumb thumb = new MoveThumb();
                    Canvas.SetLeft(thumb, point.X);
                    Canvas.SetTop(thumb, point.Y);
                    thumb.Style      = FindResource("thumbStyle") as Style;
                    thumb.Template   = FindResource("thumbTemplate") as ControlTemplate;
                    thumb.DragDelta += Thumb_DragDelta;
                    thumb.Tag        = new ThumbTag()
                    {
                        Figure       = figure,
                        IsStartPoint = false,
                        ThumbList    = thumbs
                    };

                    canvas.Children.Add(thumb);
                    thumbs.Add(thumb);
                }
            }
        }
Beispiel #2
0
        private void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            MoveThumb thumb = sender as MoveThumb;

            if (thumb != null)
            {
                double newLeft = Canvas.GetLeft(thumb) + e.HorizontalChange;
                double newTop  = Canvas.GetTop(thumb) + e.VerticalChange;

                Canvas.SetLeft(thumb, newLeft);
                Canvas.SetTop(thumb, newTop);

                ThumbTag tag = (ThumbTag)thumb.Tag;
                if (tag.IsStartPoint)
                {
                    tag.Figure.StartPoint = new Point(newLeft, newTop);
                }
                else
                {
                    int index = tag.ThumbList.IndexOf(thumb);
                    (tag.Figure.Segments[0] as PolyLineSegment).Points[index] = new Point(newLeft, newTop);
                }


                //if (index >= 0)
                //{
                //    ((first.Data as PathGeometry).Figures[0].Segments[0] as PolyLineSegment).Points[index] = new Point(newLeft, newTop);
                //    return;
                //}

                //index = startThumbs.IndexOf(thumb);
                //if (index >= 0)
                //{
                //    (first.Data as PathGeometry).Figures[index].StartPoint = new Point(newLeft, newTop);
                //    return;
                //}
            }
        }