?
Solved

WPF: Thumb DragDelta not Working

Posted on 2010-09-12
2
Medium Priority
?
2,199 Views
Last Modified: 2012-05-10
I wrote a custom adorner for the WPF InkCanvas. It takes over the built-in adorner that InkCanvas provides, and I designed it to do the same things (Select, Resize, Move, etc the adorned elements).

My Thumbs (one on each corner of a Path that has a RectangelGeomoetry locate perfectly when the adorner is added. However, the DragDelta code is not operating correctly. I'll use the TopLeft THumb as the example. As I click on the Thumb and drag it, the Thumb lags about 50-100 pixels behind the mouse point. After I let go, it places correctly, But when I select it again, it bounces back to the TopLeft corner briefly before it starts tracking.

FYI- The Thumbs are in the Adorner layer (they are not children on the InkCanvas).

Here is the code:
// Handler for thumb dragging
    void ThumbPointAdorner_OnDragDelta(object sender, DragDeltaEventArgs args)
    {
      FrameworkElement adornedElement = this.AdornedElement as FrameworkElement;
      Thumb movingThumb = sender as Thumb;

      if (adornedElement == null || movingThumb == null) return;

        {      

            if ((Math.Abs(args.HorizontalChange) > 0) || (Math.Abs(args.VerticalChange) > 0))
            {
                Rect rect = new Rect( (movingThumb as FrameworkElement).DesiredSize);

                rect.Offset(args.HorizontalChange, args.VerticalChange);

                movingThumb.Arrange(rect);
                this.UpdateLayout();
                parentElement.UpdateLayout();

            }
  
        }
    }
   
 // Arrange the Adorners.

    protected override Size ArrangeOverride(Size finalSize)
    {

      // desiredWidth and desiredHeight are the width and height of the element that's being adorned.  
      // These will be used to place the ResizingAdorner at the corners of the adorned element.  
      double desiredWidth  = _adornedElement.DesiredSize.Width;
      double desiredHeight = _adornedElement.DesiredSize.Height;

        // adornerWidth & adornerHeight are used for placement as well.
      double adornerWidth = this.DesiredSize.Width;
      double adornerHeight = this.DesiredSize.Height;

          Point topLeftPoint = new Point( InkCanvas.GetLeft(_adornedElement),
                                   InkCanvas.GetTop(_adornedElement));
                        
          IDictionary<string, Point> points = Helper.GetFourPoints(adornerHeight,
                                                            adornerWidth, 
                                                            new Point(0,0));

//        TopLeftPoint
//        TopRightPoint
//        BottomLeftPoint
//        BottomRightPoint

      {
            //_thumbs[0].Arrange( new Rect( points["TopLeftPoint"], _thumbs[0].DesiredSize));
            //_thumbs[1].Arrange( new Rect( points["TopRightPoint"], _thumbs[1].DesiredSize));
            //_thumbs[2].Arrange( new Rect( points["BottomLeftPoint"], _thumbs[2].DesiredSize));
            //_thumbs[3].Arrange(new Rect(points["BottomRightPoint"], _thumbs[3].DesiredSize));

          Size outlineSize = new Size(_adornedElement.DesiredSize.Width , _adornedElement.DesiredSize.Height );

          Rect _adornedElementRect = new Rect(outlineSize);
            
            _adornerOutline.Data = new RectangleGeometry(_adornedElementRect);
            _adornerOutline.Arrange(new Rect(outlineSize));

            _thumbs[0].Arrange( new Rect(points["TopLeftPoint"],  finalSize));
            _thumbs[1].Arrange(new Rect(points["TopRightPoint"], finalSize));
            _thumbs[2].Arrange(new Rect(points["BottomLeftPoint"], finalSize));
            _thumbs[3].Arrange(new Rect(points["BottomRightPoint"], finalSize));

      }
      // Return the final size.
      return finalSize;
    }

Open in new window

0
Comment
Question by:cardinalone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
Kumaraswamy R earned 2000 total points
ID: 33659614
0
 

Author Closing Comment

by:cardinalone
ID: 33698197
Thanks for the link,. it re-pointed my efforts. I also found a bug in my code that also was part of the solution.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question