简体   繁体   English

是否可以为path.Data设置动画

[英]Is it Possible to animate path.Data

I have code something like this: 我有这样的代码:

<Path x:Name="arrow" StrokeThickness="3" Stroke="Black"  Data="M34,115 C45,106 91,119 105,112 119,105 172,75.004352 188,82.003591" />

what I want is to animate the Data property of the path. 我想要的是动画路径的Data属性。 I'm searching this from last two days didn't find a solution. 我从最近两天搜索这个没有找到解决方案。 what I actually want is to show path bit by bit. 我真正想要的是一点一点地显示路径。

Does anyone have any Idea? 有人有什么主意吗?

"what I actually want is to show path bit by bit" “我真正想要的是一点一点地显示路径”

Do you mean something like this? 你的意思是这样的吗?

<Grid VerticalAlignment="Center" HorizontalAlignment="Center" >
    <Grid.Resources>
        <Storyboard x:Key="CWTrace">
            <!-- To run opposite direction, just swap the 'From' and 'To' values. -->
            <DoubleAnimation BeginTime="00:00:0.5" RepeatBehavior="Forever"
                         Storyboard.TargetName="arrow" 
                         Storyboard.TargetProperty="StrokeDashOffset" 
                         Duration="0:0:5" From="100" To="0"/>
        </Storyboard>
    </Grid.Resources>
    <Grid.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource CWTrace}"/>
        </EventTrigger>
    </Grid.Triggers>
    <Path x:Name="arrow" 
          StrokeDashOffset="0" StrokeDashArray="100"
          StrokeThickness="3" Stroke="Black"  
          Data="M34,115 C45,106 91,119 105,112 119,105 172,75.004352 188,82.003591"/>
</Grid>

在此输入图像描述

Obviously remove the RepeatBehavior for a one time anim, and tinker with values to get exactly what you're after. 显然,删除RepeatBehavior一次动画,并修改值以获得您正在追求的内容。 Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM