WPF:如何通过bool类型的DependencyProperty触发路径动画?
在过去的一周里,我试图找到一种触发路径动画的方法,但没有成功 我想做的是使用ViewModel中定义的布尔属性,这样当该值为true时,矩形将沿路径移动 起初我以为很容易,但 我发现的路径动画演示会通过RoutedEvent(如单击按钮或button.Loaded等)触发故事板,而我还没有通过DependencyProperty触发它的方法 我是WPF的新手,提前谢谢你 代码如下:WPF:如何通过bool类型的DependencyProperty触发路径动画?,wpf,xaml,animation,datatrigger,Wpf,Xaml,Animation,Datatrigger,在过去的一周里,我试图找到一种触发路径动画的方法,但没有成功 我想做的是使用ViewModel中定义的布尔属性,这样当该值为true时,矩形将沿路径移动 起初我以为很容易,但 我发现的路径动画演示会通过RoutedEvent(如单击按钮或button.Loaded等)触发故事板,而我还没有通过DependencyProperty触发它的方法 我是WPF的新手,提前谢谢你 代码如下: 顺便说一句,WPF很强大,但确实很难:(只需删除脚本.TargetName并使用脚本.TargetProper
顺便说一句,WPF很强大,但确实很难:(只需删除脚本.TargetName并使用脚本.TargetProperty=“RenderTransform.Matrix”:
我对wpf已经不太熟悉了,但中的答案应该会有所帮助。
<!--I define a rectangle which is expected to be auto-moving along the path when "Monitoring" is set true. -->
<Rectangle Width="20" Height="10" Fill="LightBlue">
<Rectangle.RenderTransform>
<MatrixTransform x:Name="RectangleMatrixTransform">
<MatrixTransform.Matrix >
<Matrix />
</MatrixTransform.Matrix>
</MatrixTransform>
</Rectangle.RenderTransform>
<Rectangle.Style>
<Style TargetType="Rectangle">
<Style.Triggers>
<DataTrigger Binding="{Binding Monitoring}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<!--Here I got compile exception: 'TargetName property cannot be set on a Style Setter.'-->
<MatrixAnimationUsingPath
Storyboard.TargetName="RectangleMatrixTransform"
Storyboard.TargetProperty="Matrix"
DoesRotateWithTangent="True"
Duration="0:0:5"
RepeatBehavior="Forever" >
<MatrixAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100"
PresentationOptions:Freeze="True" />
</MatrixAnimationUsingPath.PathGeometry>
</MatrixAnimationUsingPath>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</Canvas>
<Rectangle Width="20" Height="10" Fill="LightBlue">
<Rectangle.RenderTransform>
<MatrixTransform />
</Rectangle.RenderTransform>
<Rectangle.Style>
<Style TargetType="Rectangle">
<Style.Triggers>
<DataTrigger Binding="{Binding Monitoring}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<MatrixAnimationUsingPath
Storyboard.TargetProperty="RenderTransform.Matrix"
DoesRotateWithTangent="True"
Duration="0:0:5"
RepeatBehavior="Forever" >
<MatrixAnimationUsingPath.PathGeometry>
<PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100" />
</MatrixAnimationUsingPath.PathGeometry>
</MatrixAnimationUsingPath>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>