Domanda

How do I go about implementing the drag delta on a Shape, I have the following code:

void Connector_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        if (e.ClickCount == 1)
        {
            this.Focus();
            this.CaptureMouse();
            this.RaiseEvent(new DragStartedEventArgs(0,0));
            initMousePoint = e.GetPosition(this);
        }
        e.Handled = true;
    }
    void Shape2_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
    {
        currMousePoint = e.GetPosition(this);
        if (this.IsMouseCaptured)
        {
                this.RaiseEvent(new DragDeltaEventArgs(0,0);
        }
    }
    void Shape2_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        this.ReleaseMouseCapture();
    }

Now for the DragDeltaEvent args do I need to compute the drag in the mousemove and pass it to the event, also is this the right way to raise the event. If this works, then I should only subscribe to the drag delta event and use it as a thumb? Note, I do not want to template the thumb with the shape, providing this answer won't help me.


note the chagnes, about the getting the position of the mouse, this I don't think works, because it gets the position relative to the element, not the containing panel, so I don't think i will be able to find the drag distance this way.

È stato utile?

Soluzione

I solved it using:

currMousePoint = e.GetPosition(this);
double dragHorizontal = currMousePoint.X - initMousePoint.X;
double dragVertical = currMousePoint.Y - initMousePoint.Y;
//Set the new canvas top and left proeprties here.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top