wpf - 故事板 EllipseGeometry 动画
问题描述
全部。我已经启动了一个简单的 WPF 应用程序,并且想要一个按钮在它可见时遵循椭圆路径(现在我只希望它在我单击时出现......用于测试目的)。它应该简单地沿着路径移动,然后在最后一点停下来。我无法让故事板以某种风格工作。它不会引用我已经定义的路径。我该如何解决这个问题?最终,每个按钮都需要有自己的最终静止点,所以我需要在以后传递一个额外的动画。代码在 XAML 中(发布在下面)。
<Window x:Class="EllipseFollowsPath.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EllipseFollowsPath"
mc:Ignorable="d"
Title="MainWindow" Height="768" Width="1366">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Height="768" Width="1366">
<Grid.Resources>
<PathGeometry x:Key="path">
<PathGeometry.Figures>
<PathFigure StartPoint="921,384" IsClosed="False">
<ArcSegment Point="445,384" Size="60 60"
SweepDirection="Counterclockwise"/>
</PathFigure>
<PathFigure StartPoint="445,384" IsClosed="False">
<ArcSegment Point="921,384" Size="60 60"
SweepDirection="Counterclockwise"/>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
<Storyboard x:Key="sb" RepeatBehavior="Forever">
<MatrixAnimationUsingPath
Storyboard.TargetName="transform"
Storyboard.TargetProperty="Matrix"
PathGeometry="{StaticResource path}"
Duration="0:0:2">
</MatrixAnimationUsingPath>
</Storyboard>
</Grid.Resources>
<Button Height="20" Width="20">
<Button.RenderTransform>
<MatrixTransform x:Name="transform"/>
</Button.RenderTransform>
<Button.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard Storyboard="{StaticResource sb}">
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
解决方案
下面的代码有效...
<Window x:Class="EllipseFollowsPath.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EllipseFollowsPath"
mc:Ignorable="d"
Title="MainWindow" Height="768" Width="1366">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Height="768" Width="1366">
<Grid.Resources>
<PathGeometry x:Key="path">
<PathGeometry.Figures>
<PathFigure StartPoint="921,384" IsClosed="False">
<ArcSegment Point="445,384" Size="60 60"
SweepDirection="Counterclockwise"/>
</PathFigure>
<PathFigure StartPoint="445,384" IsClosed="False">
<ArcSegment Point="921,384" Size="60 60"
SweepDirection="Counterclockwise"/>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
<Storyboard x:Key="sb" RepeatBehavior="Forever">
<MatrixAnimationUsingPath
Storyboard.TargetName="transform"
Storyboard.TargetProperty="Matrix"
PathGeometry="{StaticResource path}"
Duration="0:0:2">
</MatrixAnimationUsingPath>
</Storyboard>
</Grid.Resources>
<Button Height="20" Width="20">
<Button.RenderTransform>
<MatrixTransform x:Name="transform"/>
</Button.RenderTransform>
<Button.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard Storyboard="{StaticResource sb}">
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
推荐阅读
- xml - XPath 查找具有最高值的元素
- batch-file - 将标准输出从 CD 获取到循环内的文件中
- html - 如何在 html 中创建由 DIV 元素组成的行布局
- python - 选择行和列== 0到F的熊猫数据框
- java - 为什么我们在 NamedParameterJDBCTemplate 中获取 keyholder 值时要添加 new String[]{"ID"}
- swift - 为什么 SwiftUI 项目中的工具栏文本颜色总是白色
- css - css3 转换不适用于 vue2 中的 v-for
- python - 带有 mod_wsgi 的 Apache 不在端口 80 上提供服务
- google-sheets - Google 表格 - 如何在条件格式中允许多个匹配项
- python-3.x - Discord 机器人抛出错误说你不是所有者