views:

20

answers:

0

Hi friends:

I have a class LineG inherited from a shape which will draw a simple line between two points.. I did that simply by adding two dependency properties StartPointProperty and EndPointProperty... Lastly I want to add another functionality which is MidPoint, so when I draw the line there will be a midPoint in the middle of the line. When I drag the StartPoint or EndPoint the shape will be redrawn, and when I drag the MidPoint the shape will translate depending on the MidPoint change...

private static void PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            LineG lineG = (LineG)d;
            if (e.Property.Name == "StartPoint")
            {

            }
            else if (e.Property.Name == "EndPoint")
            {

            }
            else //if MidPoint
            {
                Point p1 = (Point)e.OldValue;
                Point p2 = (Point)e.NewValue;
                double offsetX = p2.X - p1.X;
                double offsetY = p2.Y - p1.Y;

                lineG.StartPoint = new Point(lineG.StartPoint.X + offsetX, lineG.StartPoint.Y + offsetY);
                lineG.EndPoint = new Point(lineG.EndPoint.X + offsetX, lineG.EndPoint.Y + offsetY);
                lineG.MidPoint = GeneralMethods.MidPoint(lineG.StartPoint, lineG.EndPoint);
            }

            lineG.InvalidateMeasure();
        }

protected override Geometry DefiningGeometry
        {
            get
            {
                lg.StartPoint = StartPoint;
                lg.EndPoint = EndPoint;
                return lg;
            }
        }