WPF路径动画

WPF路径动画
在这里插入图片描述
前台代码

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  WindowTitle="PointAnimationUsingPath Example"
  Background="{StaticResource MyGridBrushResource}">


  <DockPanel Margin="20">
      <Border Background="#99FFFFFF" BorderBrush="#CCCCFF" BorderThickness="2"
        Margin="0,0,0,20" Padding="20" DockPanel.Dock="Top">
        <TextBlock Width="750">
          This example animates an object (rectangle) across the screen along a path. To do this, the Center property value is animated along a PathGeometry
          using PointAnimationUsingPath. The PointAnimationUsingPath object is needed because the Center property uses a point value.
        </TextBlock>
      </Border>

    <StackPanel DockPanel.Dock="Left">
    <Canvas HorizontalAlignment="Left" Width="340" Height="240" >
      
      <!-- This Path is only to show the path that the animated object will follow. -->
      <Path VerticalAlignment="Top" Margin="15,15,15,15" 
        Data="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100"
        Stroke="Black" StrokeThickness="2"
        Stretch="None" />
      
      <Path Fill="Blue" Margin="15,15,15,15">
        <Path.Data>
        
          <!-- Describes an ellipse. -->
          <EllipseGeometry x:Name="MyAnimatedEllipseGeometry"
            Center="10,100" RadiusX="15" RadiusY="15" />
        </Path.Data>
      </Path>
    </Canvas>
      

    <!-- Create a button to restart the animation. -->
    <Button Width="80" HorizontalAlignment="Left" >Start Animation
    
      <!-- Trigger and StoryBoard to initiate the animation when the button is clicked. -->
      <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
          <BeginStoryboard Name="MyBeginStoryboard">
            <Storyboard>
              
              <!-- Animates the ellipse along the path. -->
              <PointAnimationUsingPath
                Storyboard.TargetName="MyAnimatedEllipseGeometry"
                Storyboard.TargetProperty="Center"
                Duration="0:0:5" 
                RepeatBehavior="Forever" AutoReverse="True" >
                <PointAnimationUsingPath.PathGeometry>
                  <PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100" />
                </PointAnimationUsingPath.PathGeometry>
              </PointAnimationUsingPath>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Button.Triggers>
    </Button>      
    </StackPanel>
    
    <!-- Displays functional code for demonstration. -->
    <Border Background="#EEEEEE" BorderBrush="Black" BorderThickness="1">
      <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
      <TextBlock Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
      ...
      &lt;Path Margin="15,15,15,15"&gt;
        &lt;Path.Data>
        
          &lt;!-- Describes an ellipse. --&gt;
          &lt;EllipseGeometry x:Name="MyAnimatedEllipseGeometry"
             Center="10,100" RadiusX="15" RadiusY="15" /&gt;
        &lt;/Path.Data&gt;
      &lt;/Path&gt;
      ...
      &lt;Storyboard&gt;
      
        &lt;!-- Animates the ellipse along the path. --&gt;
        <Bold>&lt;PointAnimationUsingPath
           Storyboard.TargetName="MyAnimatedEllipseGeometry"
           Storyboard.TargetProperty="Center"
           Duration="0:0:5" 
           RepeatBehavior="Forever" AutoReverse="True" &gt;
             &lt;PointAnimationUsingPath.PathGeometry&gt;
               &lt;PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100" /&gt;
             &lt;/PointAnimationUsingPath.PathGeometry&gt;
         &lt;/PointAnimationUsingPath></Bold>
      &lt;/Storyboard&gt;
      ...
      </TextBlock>
      </ScrollViewer>
    </Border>
    <!-- End of code display. -->

</DockPanel>
</Page>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向着光-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值