Resizing a Node After Rotating

I’m having some issues with resizing a node (while maintaining aspect ratio) after rotating the node.

The resizing code I have that is working when the RotationAngle is 0:


protected override void DoResize(Rect newr){
 

double widthChange = newr.Width - this.AdornedNode.ActualWidth;
double heightChange = newr.Height - this.AdornedNode.ActualHeight;                

double width;
double height;                                               

if (heightChange > widthChange)
{
<span ="Apple-tab-span" style="white-space:pre">	</span>width = (newr.Height * this.AdornedNode.ActualWidth) / this.AdornedNode.ActualHeight;
<span ="Apple-tab-span" style="white-space:pre">	</span>width = Math.Round(width, 0);
<span ="Apple-tab-span" style="white-space:pre">	</span>height = newr.Height; 
}
else
{
<span ="Apple-tab-span" style="white-space:pre">	</span>width = newr.Width;
<span ="Apple-tab-span" style="white-space:pre">	</span> height = (newr.Width * this.AdornedNode.ActualHeight) / this.AdornedNode.ActualWidth;
<span ="Apple-tab-span" style="white-space:pre">	</span>height = Math.Round(height, 0);
}

Point topLeft; 


double left = this.AdornedNode.Location.X - (this.AdornedNode.ActualWidth / 2);
double right = this.AdornedNode.Location.X + (this.AdornedNode.ActualWidth / 2);
double top = this.AdornedNode.Location.Y - (this.AdornedNode.ActualHeight / 2);
double bottom = this.AdornedNode.Location.Y + (this.AdornedNode.ActualHeight / 2);

switch (this.ResizingAnchor)
{
<span ="Apple-tab-span" style="white-space:pre">	</span>case "TopLeft":
<span ="Apple-tab-span" style="white-space:pre">		</span>topLeft = new Point((right - width), (bottom - height));
<span ="Apple-tab-span" style="white-space:pre">		</span>break;
<span ="Apple-tab-span" style="white-space:pre">	</span>case "TopRight":
<span ="Apple-tab-span" style="white-space:pre">		</span> topLeft = new Point(left, (bottom - height));
<span ="Apple-tab-span" style="white-space:pre">		</span>break;
<span ="Apple-tab-span" style="white-space:pre">	</span>case "BottomLeft":
<span ="Apple-tab-span" style="white-space:pre">		</span>topLeft = new Point((right - width), top);
<span ="Apple-tab-span" style="white-space:pre">		</span>break;
<span ="Apple-tab-span" style="white-space:pre">	</span>default:
<span ="Apple-tab-span" style="white-space:pre">		</span>topLeft = newr.Location;
<span ="Apple-tab-span" style="white-space:pre">		</span>break;
}


newr = new Rect(topLeft.X, topLeft.Y, width, height);

base.DoResize(newr);
}

I’m having trouble wrapping my head around how the resizing is working with rotated nodes and was hoping to get steered in the right direction.

Thanks
Ryan

What’s wrong with what it normally does? It seems to work fine, as shown in the Draggable Link sample.

The problem is that it doesn’t normally maintain the aspect ratio of the node when resizing, which we would like to have.

Instead of overriding DoResize, override ComputeResize to just call the base method with the last argument false instead of true.

Of course you could decide on the value of that boolean last argument dynamically, such as whether IsShiftKeyDown().