Rotating an element while rendering
When you want to rotate an element at runtime, the RotateTransform
is used. It rotates the element around a center position denoted by CenterX
and CenterY
, at an angle in degrees specified by the Angle
property.
Let's learn how to use RotateTransform
to rotate a UI element at a specified angle. In this recipe, we are going to discuss this.
Getting ready
Open Visual Studio and create a new project named CH08.RotateTransformDemo
. Make sure to select the WPF App
template while creating the project.
How to do it...
Follow the steps mentioned here to apply rotation to an Image
control:
- From
Solution Explorer
, right-click on the project node and create a new folder. Name it asImages
. - Now right-click on the
Images
folder and add an existing image from your system. Name itimage1.png
. - Open the
MainWindow.xaml
file and replace the existingGrid
with a horizontalStackPanel
. - Insert the following XAML mark-up inside the
StackPanel
to add two images the application window...