C#的WPF程序,如何使Canvas有旋转效果
展开全部
不知道提问者指的旋转效果是咋样的,所以就做了两种不同的。有啥问题尽管问哈^ ^
<Window.Resources>
<Storyboard x:Key="ScaleTransformStoryboard">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:02" RepeatBehavior="Forever" Storyboard.TargetName="canvas1"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<SplineDoubleKeyFrame Value="1"/>
<SplineDoubleKeyFrame Value="-1"/>
<SplineDoubleKeyFrame Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="RotateTransformStoryboard">
<DoubleAnimation Storyboard.TargetName="canvas2" From="0" To="359" BeginTime="00:00:00" Duration="00:00:05" RepeatBehavior="Forever"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" >
</DoubleAnimation>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource ScaleTransformStoryboard}"/>
<BeginStoryboard Storyboard="{StaticResource RotateTransformStoryboard}"/>
</EventTrigger>
</Window.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Canvas x:Name="canvas1" Width="100" Height="100" Background="Aquamarine" Grid.Column="0">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
<Canvas x:Name="canvas2" Width="100" Height="100" Background="Aquamarine" Grid.Column="1">
<Canvas.RenderTransform>
<TransformGroup>
<RotateTransform Angle="0" CenterX="0" CenterY="0"/>
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
</Grid>
<Window.Resources>
<Storyboard x:Key="ScaleTransformStoryboard">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:02" RepeatBehavior="Forever" Storyboard.TargetName="canvas1"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<SplineDoubleKeyFrame Value="1"/>
<SplineDoubleKeyFrame Value="-1"/>
<SplineDoubleKeyFrame Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="RotateTransformStoryboard">
<DoubleAnimation Storyboard.TargetName="canvas2" From="0" To="359" BeginTime="00:00:00" Duration="00:00:05" RepeatBehavior="Forever"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)" >
</DoubleAnimation>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource ScaleTransformStoryboard}"/>
<BeginStoryboard Storyboard="{StaticResource RotateTransformStoryboard}"/>
</EventTrigger>
</Window.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Canvas x:Name="canvas1" Width="100" Height="100" Background="Aquamarine" Grid.Column="0">
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
<Canvas x:Name="canvas2" Width="100" Height="100" Background="Aquamarine" Grid.Column="1">
<Canvas.RenderTransform>
<TransformGroup>
<RotateTransform Angle="0" CenterX="0" CenterY="0"/>
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
</Grid>
追问
啊?谢谢啊,我前段时间不在,今天刚回来,我想让CANVAS可以按自定义角度旋转?可以吗?
中间应该加些什么呢???我像在程序代码中控制旋转角度~
追答
里设置的初始角度。里设置的是动画中的旋转角度。你先运行下我给你的代码,看下你要的究竟是何种效果。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询