如果您不使用按钮或其他机制来应用转换,则可以仅在 XAML 中定义它
<Rectangle Fill="#FFF4F4F5"
Name="rect"
HorizontalAlignment="Left"
Height="225"
Margin="84,39,0,0"
Stroke="Black"
VerticalAlignment="Top"
Width="299">
<Rectangle.RenderTransform>
<TransformGroup>
<SkewTransform AngleX="45"
AngleY="0"
CenterX="-50"
CenterY="50" />
<RotateTransform Angle="30" />
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
如果添加触发器部分,则可以使其具有交互性。
<Rectangle Fill="#FFF4F4F5"
Name="rect"
HorizontalAlignment="Left"
Height="225"
Margin="84,39,0,0"
Stroke="Black"
VerticalAlignment="Top"
Width="299">
<Rectangle.RenderTransform>
<TransformGroup>
<SkewTransform AngleX="45"
AngleY="0"
CenterX="-50"
CenterY="50" />
<RotateTransform x:Name="RotateTransform"
Angle="0" />
</TransformGroup>
</Rectangle.RenderTransform>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.MouseDown">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="RotateTransform"
Storyboard.TargetProperty="Angle"
To="360"
Duration="0:0:5"
FillBehavior="Stop" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>