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 8638243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:40:51+00:00 2026-06-12T10:40:51+00:00

I have created a draggable control that want to restrict to the boundaries of

  • 0

I have created a draggable control that want to restrict to the boundaries of it’s containing grid (i.e. not let the user drag it outside of the grid).

I need a test that returns true or false so that I can cancel the drag if necessary.

I have looked at VisualTreeHelper.FindElementsInHostCoordinates and TransformToVisual etc, but I cannot find a simple way of doing it without lots of checks for each of the corners of the control.

e.g. some code (Dialog is the name of the control that is being dragged):

MouseEventHandler mouseMove = (s, args) =>
        {
            var transform = new TranslateTransform();
            transform.X = args.GetPosition(Dialog).X - _mouseDownPosition.X;
            transform.Y = args.GetPosition(Dialog).Y - _mouseDownPosition.Y;

            if (transformGroup != null)
            {
                transformGroup.Children.Add(transform);
                Dialog.RenderTransform = transformGroup;
            }

        };
  • 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-12T10:40:52+00:00Added an answer on June 12, 2026 at 10:40 am

    Thanks. In the end I took another approach; instead of trying to stop the user from dragging ANY of the child control outside of the boundary of the container I have only stopped them from dragging the pointer outside the boundary, e.g. in the mousemove eventhandler:

    if ((args.GetPosition(parentGrid).X < 0 || args.GetPosition(parentGrid).Y < 0))
    {
        return; // don't do a translatetransform
    }
    

    The problem with this was that the parts of the child control were visible outside of the container.

    What I did was set the Clip property of the parent control so that the parts of the child outside of the boundary are hidden.

    e.g.:

    var clipRegion = new RectangleGeometry();
    clipRegion.Rect = new Rect(0, 0, elementParent.ActualWidth, elementParent.ActualHeight);
    elementParent.SetValue(Canvas.ClipProperty, clipRegion);
    

    This seems to work quite nicely!

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

Sidebar

Related Questions

I have a list of items that I want to make draggable. I am
I have a form created in Windows Forms which is draggable wherever I click.
I have created some JQuery that will expand a div 'popup' on hover and
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a function that shows/hides different messages according to a combination of
I have created a simple grid widget but it sticks to the browser window.
I have draggable items that can be cloned. I wanted each clone to be
I have a ListView-derived class which creates a bunch of user controls that are
in my app I have some sprites that i need to drag and drop
i have created the drag and drop work. Here i can place the drag

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.