Storyboard.TargetProperty和Path [英] Storyboard.TargetProperty and Path

查看:60
本文介绍了Storyboard.TargetProperty和Path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含带有PathFigures的PathGeometry的Path,我希望使用Storyboard进行动画处理。在动画(例如DoubleAnimation)中,我需要访问PathSegments的Point属性(在我的例子中,它将是一个ArcSegment)。我所遇到的
麻烦在于弄清楚如何指定Storyboard.TargetProperty。部分原因是因为属性需要转换(例如,路径的Data属性是Geometry类型,即使我已经为它指定了PathGeometry)。另外,
我需要指定索引对于几个属性(例如,PathGeometry的Figures属性)。当我想在此类场景中为属性设置动画时,如何指定Storyboard.TargetProperty?谢谢。



Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

< blockquote>

如果要将动画应用于路径,可以使用PointAnimation


http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.animation。 pointanimation


例如:


路径:

< ; Path Stroke =" Blue" StrokeThickness = QUOT; 2英寸名称= QUOT;路径"> 
< Path.Data>
< PathGeometry>
< PathGeometry.Figures>
< PathFigure>
< PathFigure.Segments>
< LineSegment Point =" 0,100" />
< LineSegment Point =" 300,100" />
< ArcSegment x:Name =" arc"点= QUOT; 30500"大小= QUOT; 10,10 QUOT; />
< /PathFigure.Segments>
< / PathFigure>
< PathFigure>
< PathFigure.Segments>
< LineSegment Point =" 20,100" />
< /PathFigure.Segments>
< / PathFigure>
< /PathGeometry.Figures>
< / PathGeometry>
< /Path.Data>
< / Path>

如果将动画应用于ArcSegment,您可以尝试:

 <故事板> 
< PointAnimation Duration =" 0:0:1"从= QUOT; 30500"为了= QUOT; 30100" Storyboard.TargetName = QUOT;路径" Storyboard.TargetProperty = QUOT;(Path.Data)(PathGeometry.Figures)[0](PathFigure.Segments)[2](ArcSegment.Point)QUOT。; EnableDependentAnimation = QUOT;真" />
< / Storyboard>

< Storyboard> 
< PointAnimation Duration =" 0:0:1"从= QUOT; 30500"为了= QUOT; 30100" Storyboard.TargetName = QUOT;弧" Storyboard.TargetProperty = QUOT; ArcSegment.Point" EnableDependentAnimation = QUOT;真" />
< / Storyboard>




I have a Path containing a PathGeometry with PathFigures that I want to animate using a Storyboard. In the animations (such as DoubleAnimation), I need to access the Point property of the PathSegments (in my case, it will be an ArcSegment). What I am having trouble doing is figuring out how to specify the Storyboard.TargetProperty. Part of the reason for this is because the properties need converted (for example, the Data property of a path is of type Geometry, even though I have assigned it a PathGeometry). Also, I need to specify indexes for several of the properties (for example, the Figures property of PathGeometry). How do I specify the Storyboard.TargetProperty when I want to animate properties in this type of scenario? Thanks.


Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

Hi, you can use PointAnimation if you want to apply animattion to a Path

http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.animation.pointanimation

For example:

a path:

<Path Stroke="Blue" StrokeThickness="2" Name="path">
    <Path.Data>
        <PathGeometry>
            <PathGeometry.Figures>
                <PathFigure>
                    <PathFigure.Segments>
                        <LineSegment Point="0,100"/>
                        <LineSegment Point="300,100"/>
                        <ArcSegment x:Name="arc" Point="30,500" Size="10,10"/>
                    </PathFigure.Segments>
                </PathFigure>
                <PathFigure>
                    <PathFigure.Segments>
                        <LineSegment Point="20,100"/>
                    </PathFigure.Segments>
                </PathFigure>
            </PathGeometry.Figures>
        </PathGeometry>
    </Path.Data>
</Path>

and if apply animation to ArcSegment, you can try:

<Storyboard>
    <PointAnimation Duration="0:0:1" From="30,500" To="30,100" Storyboard.TargetName="path" Storyboard.TargetProperty="(Path.Data).(PathGeometry.Figures)[0].(PathFigure.Segments)[2].(ArcSegment.Point)" EnableDependentAnimation="True"/>
</Storyboard>

Or

<Storyboard>
    <PointAnimation Duration="0:0:1" From="30,500" To="30,100" Storyboard.TargetName="arc" Storyboard.TargetProperty="ArcSegment.Point" EnableDependentAnimation="True"/>
</Storyboard>


这篇关于Storyboard.TargetProperty和Path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆