日期:2014-05-18  浏览次数:20943 次

WPF实现一个简单动画
<Window x:Class="WpfApplication1.Window6"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window6" Height="300" Width="300">
<Image>
  <Image.Source>
  <DrawingImage>
  <DrawingImage.Drawing>
  <GeometryDrawing>
  <GeometryDrawing.Pen>
  <Pen Brush="Blue" Thickness="30"/>
  </GeometryDrawing.Pen>
  <GeometryDrawing.Geometry>
  <PathGeometry>
  <PathFigure StartPoint="10,100">
  <LineSegment x:Name="line1" Point="10,100" IsSmoothJoin="True"/>
  <LineSegment x:Name="line2" Point="10,100" IsSmoothJoin="True"/>
  </PathFigure>
  </PathGeometry>
  </GeometryDrawing.Geometry>
  </GeometryDrawing>
  </DrawingImage.Drawing>
  </DrawingImage>
  </Image.Source>
  <Image.Triggers>
  <EventTrigger RoutedEvent="Image.Loaded">
  <BeginStoryboard>
  <Storyboard RepeatBehavior="Forever">
  <PointAnimation Storyboard.TargetName="line1" Storyboard.TargetProperty="Point" From="10,100" To="100,200" Duration="0:0:2" BeginTime="0:0:1"/>  
  <PointAnimation Storyboard.TargetName="line2" Storyboard.TargetProperty="Point" From="100,200" To="200,10" Duration="0:0:2" BeginTime="0:0:3"/>
  </Storyboard>
  </BeginStoryboard>
  </EventTrigger>
  </Image.Triggers>
  </Image>
</window>
  用一个image显示一个简单的“打钩”效果的动画,但整个image会随着动画的过程而改变自身的大小,我想实现的是image大小固定,然后动画中的点是相对于image的位置,而不是相对于window。
  当然,如果有更好的实现“打钩”动画的方法也可以介绍给我,本人新手,说的时候详细点,谢谢。

------解决方案--------------------