Assuming you have Thumbs inside an adorner to drag / rotate, etc., you will first want to stop them from scaling so that you do this in an override of GetDesiredTransform. Apply the return scale that you applied to the framework element. This makes your thumbs not scalable when resized.
public override GeneralTransform GetDesiredTransform(GeneralTransform transform) { double scaleFactor = GetCurrentScaleFactor(this._parent); if (this._visualChildren != null) { foreach (var thumb in this._visualChildren.OfType<Thumb>()) { thumb.RenderTransform = new ScaleTransform(1 / scaleFactor , 1 / scaleFactor ); thumb.RenderTransformOrigin = new Point(0.5, 0.5); } } return base.GetDesiredTransform(transform); }
The next problem will be to create the thumbs so that they are in the right places after scaling / rotation, etc. Since you changed the render transformation for the thumb, you also need to manually organize it using ArrangeOverride.
To do this, save a list of all your thumbs and what positions they should be. If you deal only with square elements, your work is done halfway because you only need to deal with corners and sides.
protected override Size ArrangeOverride(Size finalSize) { var adornedElement = this.AdornedElement as FrameworkElement;
If you do not know how to arrange, see this project project article .
If you still can't get it to work, show us the appropriate code (rather than a visual studio solution) that is likely to cause problems and someone will help you, I'm sure.
EDIT
Simplify your code first to understand your problem.
- Remove all thumbs and event handlers except the btmRight thumb.
- Add a DragCompleted event to btmRight Thumb. (Remove the drag delta)
Essentially, the essence of your problem code comes down to a commented line:
void _btmRight_DragCompleted(object sender, DragCompletedEventArgs e) { var adornedElement = AdornedElement as FrameworkElement; var hitThumb = sender as Thumb; if (adornedElement == null || hitThumb == null) return; var transformGroup = new TransformGroup(); transformGroup.Children.Add(adornedElement.RenderTransform);
Now itโs easy to understand the problem. This piece of code works great when dragging and resizing for the first time. This is because adornedElement.Width and adornedElement.Height are true when you drag it for the first time until scale transforms are applied. Once your drag and drop is complete, you assume that now the width and height will be the new width and height. This is not true! You see that this is just a transformation of the visualization, it does not change the width or height of the element. It just makes it bigger.
So what you need to do, first apply the existing scale transformation to the width and height, getting the visualized width and height. Then calculate the scale transform using these new values โโand add the transform to the group. Then you get what you want.
You will most likely have other problems when you do this in DragDelta. But in this case, you should ask a more specific question with only a small amount of relevant code , and you will get an answer from someone in a few minutes, I'm sure.