李大军

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 <Window.Resources>
 2         <Style  x:Key="ImageAnimationStyle" TargetType="Image">
 3             <Style.Triggers>
 4                 <DataTrigger Binding="{Binding IsRotate}" Value="true">
 5                     <DataTrigger.EnterActions>
 6                         <BeginStoryboard x:Name="b">
 7                             <Storyboard>
 8                                 <DoubleAnimation 
 9                                     Storyboard.TargetProperty="(Image.RenderTransform).(RotateTransform.Angle)"
10                                     To="60" 
11                                     RepeatBehavior="Forever"
12                                     AutoReverse="True"
13                                     Duration="0:0:0.5">
14                                 </DoubleAnimation>
15                             </Storyboard>
16                         </BeginStoryboard>
17                     </DataTrigger.EnterActions>
18                     <DataTrigger.ExitActions>
19                         <StopStoryboard BeginStoryboardName="b"/>
20                     </DataTrigger.ExitActions>
21                 </DataTrigger>
22             </Style.Triggers>
23         </Style>
24     </Window.Resources>
25 
26 
27     <Window.DataContext>
28         <local:Datas/>
29     </Window.DataContext>
30     <Grid >
31         <Grid.RowDefinitions>
32             <RowDefinition Height="28*"/>
33             <RowDefinition Height="407*"/>
34         </Grid.RowDefinitions>
35         
36         <StackPanel Orientation="Horizontal">
37             <Button Content="start" Width="100" Command="{Binding StartRotateCmd}"/>
38             <Button Content="stop" Width="100" Command="{Binding StopRotateCmd}"/>
39 
40         </StackPanel>
41         <Viewbox Grid.Row="1">
42             <Image Style="{StaticResource ImageAnimationStyle}" Source="pack://application:,,,/通风风扇.png" Width="200" Margin="300,0,300,0" >
43                 <Image.RenderTransform>
44                     <RotateTransform CenterX="100" CenterY="100"/>
45                 </Image.RenderTransform>
46             </Image>
47         </Viewbox>
48         
49     </Grid>

 

posted on 2021-11-07 14:18  李大军  阅读(357)  评论(0编辑  收藏  举报