public static readonly DependencyProperty AngleProperty;
public static readonly DependencyProperty CenterXProperty;
public static readonly DependencyProperty CenterYProperty;
public RotateTransform();
public RotateTransform(double angle);
public RotateTransform(double angle, double centerX, double centerY);
public double Angle { get; set; }
public double CenterX { get; set; }
public double CenterY { get; set; }
public override Matrix Value { get; }
public RotateTransform Clone();
public RotateTransform CloneCurrentValue();
protected override Freezable CreateInstanceCore();
Angle属性表示获取或设置顺时针旋转的角度(以度为单位)。默认值是0度。CenterX 和CenterY 表示获取或设置旋转中心点的 x y坐标,Value属性表示当前转换的矩阵。通常我们只需要设置Angle、CenterX 和CenterY即可。
一、RotateTransform示例
<Window x:Class="HelloWorld.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HelloWorld"
xmlns:controls="clr-namespace:HelloWorld.Controls"
xmlns:helper="clr-namespace:HelloWorld.MVVM"
mc:Ignorable="d" Background="Lavender"
MouseMove="Window_MouseMove"
Title="WPF中文网 - www.wpfsoft.com" Height="350" Width="500">
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Width="100"
Height="25"
Content="RotateTransform"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button.RenderTransform>
<RotateTransform Angle="{Binding ElementName=slider,Path=Value}"/>
</Button.RenderTransform>
</Button>
<Button Grid.Column="1"
Width="100"
Height="25"
Content="RotateTransform"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button.RenderTransform>
<RotateTransform Angle="{Binding ElementName=slider,Path=Value}"
CenterX="50" CenterY="12.5"/>
</Button.RenderTransform>
</Button>
<Button x:Name="button"
Grid.Column="2"
Width="100"
Height="25"
Content="RotateTransform"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button.RenderTransform>
<RotateTransform Angle="45"/>
</Button.RenderTransform>
</Button>
<Slider x:Name="slider"
Grid.ColumnSpan="3"
Margin="30"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Value="0"
Maximum="720"
Width="400" />
</Grid>
</Window>
private void Window_MouseMove(object sender, MouseEventArgs e)
if (button.RenderTransform is RotateTransform rotateTransform)
Point point = e.GetPosition(this);
rotateTransform.Angle = point.X + point.Y;