Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:39:28+00:00 2026-06-07T02:39:28+00:00

So I have a Border with a TranslateTransform so that I can move it

  • 0

So I have a Border with a TranslateTransform so that I can move it around my window. Within the contents of the Border I have a number of controls plus a ScrollViewer. The dragging works fine but when I click the scrollbar the whole border jumps so that my cursor is now over the last point at which I clicked. Very annoying and I can’t see why it’s happening to my scrollbar but not my other controls.

(I’m using Denis Morozov’s simple, excellent guide http://denismorozov.blogspot.ie/2008/01/drag-controls-in-wpf-using.html)

Here’s what I’m doing in code;

private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
    {
        this.current.X = Mouse.GetPosition((IInputElement)sender).X;
        this.current.Y = Mouse.GetPosition((IInputElement)sender).Y;

        // Ensure object receives all mouse events.
        this.current.InputElement.CaptureMouse();
    }

    private void Canvas_MouseUp(object sender, MouseButtonEventArgs e)
    {
        if (this.current.InputElement != null)
            this.current.InputElement.ReleaseMouseCapture();
    }

    private void Canvas_MouseMove(object sender, MouseEventArgs e)
    {
        // if mouse is down when its moving, then it's dragging current
        if (e.LeftButton == MouseButtonState.Pressed)
            this.current.IsDragging = true;
        else
            this.current.IsDragging = false;

        if (this.current.IsDragging && current.InputElement != null)
        {
            // Retrieve the current position of the mouse.
            double newX = Mouse.GetPosition((IInputElement)sender).X;
            double newY = Mouse.GetPosition((IInputElement)sender).Y;

            // Reset the location of the object (add to sender's renderTransform

            // newPosition minus currentElement's position
            Transform rt = ((UIElement)this.current.InputElement).RenderTransform;
            double offsetX = rt.Value.OffsetX;
            double offsetY = rt.Value.OffsetY;
            rt.SetValue(TranslateTransform.XProperty, offsetX + newX - current.X);
            rt.SetValue(TranslateTransform.YProperty, offsetY + newY - current.Y);

            // Update position of the mouse
            current.X = newX;
            current.Y = newY;
        }
    }

    public void MouseLeftBtnDown(object sender, MouseButtonEventArgs e)
    {
        this.current.InputElement = (IInputElement)sender;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:39:30+00:00Added an answer on June 7, 2026 at 2:39 am

    Found it actually in the comments on Denis’ page. Problem lay in not resetting things on Canvas_MouseUp. That method should actually be;

    if (this.current.InputElement != null)
    {
    this.current.IsDragging = false;
    this.current.InputElement.ReleaseMouseCapture();
    this.current.InputElement = null;
    }
    

    Now works like a charm 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a window with a solid border around it. How can I remove
How can I draw a rectangle that have a black border and white background?
I have a UserControl with a Border element within it that I want to
I would like to have a border that is 4px thick pink on the
I would like to have fuzzy looking border around my Canvas control. Basically, I
I want to have a border around ListViewItem (row in my case). ListView source
Is it possible to have a border around an image which is a link
I currently have two divs on my site: Notice that both have border [same
Hope that my question is easy enough :) I have BORDER as main container
I have the following: <table class=floatleft style=margin-right:1em;margin-bottom:1em;border:4px;> Although I have a border around the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.