Answered by:
problem with Adorner when rotating Shape

Question
-
i draw shape say rectangle and it has four adorners in its corners when i resize the shape using adorners it works very well
(if the resize it using top-left the bottom-right must be fixed )
but when i rotate the shape the four adorners moves in the same time when i try to resize it
how i can make the adorners work like before rotating the shape
thank you
Monday, April 11, 2011 12:28 PM
Answers
-
the problem was RenderTransformOrigin of the shape i was created it was always give me in point(0,0)
so when i create new shape i transform its RenderTransformOrigin to point (0.5,0.5)
and i use the same calculations like above and it's now working
@Yves.Z thank you so much
Tuesday, April 19, 2011 1:38 PM
All replies
-
Hi Egyptian Coder,
Without having a look at your code, I assume that you are using LayoutTransform to Rotate your shape. Please try to use RenderTransform instead and see if it solved.
I wrote a simple demo for showing rotation operations on a shape with adorners. Hope this would help you work it out.
http://cid-e52a44742984b88f.office.live.com/self.aspx/.Documents/TrigonometricDemo.zip
If the problem persists, please feel free to post back and elaborate it.
Best regards
Yves Zhang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Wednesday, April 13, 2011 7:58 AM -
@Yves unfortunately its not what i need
in this article http://www.codeproject.com/KB/WPF/WPFDiagramDesigner_Part1.aspx
he solve this problem by adding this lines in DragDelta of the thumb
Canvas.SetTop(this.designerItem, Canvas.GetTop(this.designerItem) + (this.transformOrigin.Y * deltaVertical * (1 - Math.Cos(-this.angle))));
Canvas.SetLeft(this.designerItem, Canvas.GetLeft(this.designerItem) - deltaVertical * this.transformOrigin.Y * Math.Sin(-this.angle));but i can't understand what he did because i use adorners different way
this is my code to handle Top right thumb but it causes the previous problem
void HandleTopRight(object sender, DragDeltaEventArgs args) { FrameworkElement adornedElement = this.AdornedElement as FrameworkElement; Thumb hitThumb = sender as Thumb; if (adornedElement.IsEnabled) { if (adornedElement == null || hitThumb == null) return; FrameworkElement parentElement = adornedElement.Parent as FrameworkElement; // Ensure that the Width and Height are properly initialized after the resize. EnforceSize(adornedElement); // Change the size by the amount the user drags the mouse, as long as it's larger // than the width or height of an adorner, respectively. adornedElement.Width = Math.Max(adornedElement.Width + args.HorizontalChange, hitThumb.DesiredSize.Width); //adornedElement.Height = Math.Max(adornedElement.Height - args.VerticalChange, hitThumb.DesiredSize.Height); double height_old = adornedElement.Height; double height_new = Math.Max(adornedElement.Height - args.VerticalChange, hitThumb.DesiredSize.Height); double top_old = Canvas.GetTop(adornedElement); adornedElement.Height = height_new; Canvas.SetTop(adornedElement, top_old - (height_new - height_old)); } }
Thursday, April 14, 2011 1:25 PM -
The author of the article you referred calculated the new coordinates when he applied rotetaion transform.
Ok, so how did it work if you go the way I mentioned in previous post?
It seems the problem is that you are not handling your thumbs positions appropriatlly. Maybe you could offer more code of your app, so I can help you find the point.
Best regards
Yves Zhang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, April 18, 2011 5:30 AM -
the problem was RenderTransformOrigin of the shape i was created it was always give me in point(0,0)
so when i create new shape i transform its RenderTransformOrigin to point (0.5,0.5)
and i use the same calculations like above and it's now working
@Yves.Z thank you so much
Tuesday, April 19, 2011 1:38 PM -
I am glad to see you got it to work, and thank you for sharing your experience here!
Have a nice day!
Yves Zhang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Wednesday, April 20, 2011 3:31 AM