Prev | Current Page 679 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

(If the shape
region isn??™t square, the coordinate system is stretched accordingly.)
With the help of the RenderTransformOrigin property, you can rotate any shape around
its center point using markup like this:
Canvas.Left="100" Canvas.Top="100" RenderTransformOrigin="0.5,0.5">




This works because the point (0.5, 0.5) designates the center of the shape, regardless of
its size. In practice, RenderTransformOrigin is generally more useful than the CenterX and
CenterY properties, although you can use either one (or both) depending on your needs.
nTip You can use values greater than 1 or less than 0 when setting RenderTransformOrigin property to
designate a point that appears outside the bounding box of your shape. For example, you can use this technique
with a RotateTransform to rotate a shape in a large arc around a very distant point, such as (5, 5).
Transforming Elements
The RenderTransform and RenderTransformOrigin properties aren??™t limited to shapes. In fact,
the Shape class inherits them from the UIElement class, which means they??™re supported by all
WPF elements, including buttons, text boxes, the TextBlock, entire layout containers full of
content, and so on.


Pages:
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691