WPF实现一个简单动画

woshinia 2012-03-11 04:27:41
<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。
当然,如果有更好的实现“打钩”动画的方法也可以介绍给我,本人新手,说的时候详细点,谢谢。
...全文
209 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
烟波钓 2012-03-15
  • 打赏
  • 举报
回复
woshinia 2012-03-15
  • 打赏
  • 举报
回复
<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="500" Width="500">

<Image Stretch="None">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Transparent" Thickness="30"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry>
<PathFigure StartPoint="10,100">
<LineSegment x:Name="line3" Point="100,200" IsSmoothJoin="True"/>
<LineSegment x:Name="line4" Point="200,10" IsSmoothJoin="True"/>
</PathFigure>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<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>
</DrawingGroup>
</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:1" BeginTime="0:0:1"/>
<PointAnimation Storyboard.TargetName="line2" Storyboard.TargetProperty="Point" From="100,200" To="200,10" Duration="0:0:1" BeginTime="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>

</Window>
问题已解决,通过先画一个透明的相同图形,即可达到固定画面的作用。

开始送分,欢迎回复
woshinia 2012-03-15
  • 打赏
  • 举报
回复
自己顶一个,求解

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧