当前位置:   article > 正文

基于vs和C#的WPF应用之动画5---变大矩形

基于vs和C#的WPF应用之动画5---变大矩形

1.添加Blend包

 

2.标签引入
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
 3.设计矩形样式
  1. <Style x:Key="rec" TargetType="Rectangle">
  2. <Setter Property="Width" Value="10"/>
  3. <Setter Property="Height" Value="30"/>
  4. <Setter Property="Fill" Value="#f1404b"/>
  5. </Style>
4.设置动画故事板
  1. <Storyboard x:Key="fifth_sb" RepeatBehavior="Forever" Storyboard.TargetProperty="Height">
  2. <DoubleAnimation Storyboard.TargetName="rec1" To="50" BeginTime="0:0:0.0" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  3. <DoubleAnimation Storyboard.TargetName="rec2" To="50" BeginTime="0:0:0.2" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  4. <DoubleAnimation Storyboard.TargetName="rec3" To="50" BeginTime="0:0:0.4" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  5. <DoubleAnimation Storyboard.TargetName="rec4" To="50" BeginTime="0:0:0.6" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  6. <DoubleAnimation Storyboard.TargetName="rec5" To="50" BeginTime="0:0:0.8" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  7. </Storyboard>
5.设置缓动函数
<PowerEase x:Key="powerEase" Power="3" EasingMode="EaseInOut"/>
6.设置触发器启动动画
  1. <Grid.Triggers>
  2. <EventTrigger RoutedEvent="Loaded">
  3. <BeginStoryboard Storyboard="{StaticResource fifth_sb}"/>
  4. </EventTrigger>
  5. </Grid.Triggers>

7.整体

  1. <Window x:Class="Animate2.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. mc:Ignorable="d"
  7. Title="MainWindow" Height="450" Width="800">
  8. <Grid Background="White" HorizontalAlignment="Center">
  9. <Grid.Resources>
  10. <Style x:Key="rec" TargetType="Rectangle">
  11. <Setter Property="Width" Value="10"/>
  12. <Setter Property="Height" Value="30"/>
  13. <Setter Property="Fill" Value="#f1404b"/>
  14. </Style>
  15. <PowerEase x:Key="powerEase" Power="3" EasingMode="EaseInOut"/>
  16. <Storyboard x:Key="fifth_sb" RepeatBehavior="Forever" Storyboard.TargetProperty="Height">
  17. <DoubleAnimation Storyboard.TargetName="rec1" To="50" BeginTime="0:0:0.0" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  18. <DoubleAnimation Storyboard.TargetName="rec2" To="50" BeginTime="0:0:0.2" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  19. <DoubleAnimation Storyboard.TargetName="rec3" To="50" BeginTime="0:0:0.4" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  20. <DoubleAnimation Storyboard.TargetName="rec4" To="50" BeginTime="0:0:0.6" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  21. <DoubleAnimation Storyboard.TargetName="rec5" To="50" BeginTime="0:0:0.8" Duration="0:0:0.5" EasingFunction="{StaticResource powerEase}" AutoReverse="True"/>
  22. </Storyboard>
  23. </Grid.Resources>
  24. <Grid.Triggers>
  25. <EventTrigger RoutedEvent="Loaded">
  26. <BeginStoryboard Storyboard="{StaticResource fifth_sb}"/>
  27. </EventTrigger>
  28. </Grid.Triggers>
  29. <Grid.ColumnDefinitions>
  30. <ColumnDefinition Width="15"/>
  31. <ColumnDefinition Width="15"/>
  32. <ColumnDefinition Width="15"/>
  33. <ColumnDefinition Width="15"/>
  34. <ColumnDefinition Width="15"/>
  35. </Grid.ColumnDefinitions>
  36. <Label Content="Loading"
  37. FontSize="18"
  38. FontFamily="Times New Roman"
  39. Foreground="#252c41"
  40. FontWeight="Bold"
  41. Grid.ColumnSpan="5"
  42. VerticalContentAlignment="Center"
  43. HorizontalContentAlignment="Center"
  44. Margin="0,100,0,0"/>
  45. <Rectangle Name="rec1" Grid.Column="0" Style="{StaticResource rec}"/>
  46. <Rectangle Name="rec2" Grid.Column="1" Style="{StaticResource rec}"/>
  47. <Rectangle Name="rec3" Grid.Column="2" Style="{StaticResource rec}"/>
  48. <Rectangle Name="rec4" Grid.Column="3" Style="{StaticResource rec}"/>
  49. <Rectangle Name="rec5" Grid.Column="4" Style="{StaticResource rec}"/>
  50. </Grid>
  51. </Window>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/571921
推荐阅读
相关标签
  

闽ICP备14008679号