none
请问Polygon中Points怎么用动画形式改变呢? RRS feed

  • 问题

  • PointAnimation支持一个点,doubleAnimation支持一个值,请问如何用动画形式改变polygon中的points属性?

    2008年11月3日 13:48

答案

  • 我想楼主要把思路改一下,当我看到你的贴时做测试也做了一段时间,突然想明白了,Polygon的Points集合是没法加动画的,Polygon只是为了,做图标……,做动画也无非是整体变化,要是想做形状的变形动画可以用Path,我写了个简单的Demo希望对你有帮助。

     

    <UserControl
        x:Class="SilverlightApplication1.Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >
        <Grid>
            <StackPanel
                Orientation="Vertical"
            >
                <Path
                    Fill="RoyalBlue"
              Stroke="Orange"
              StrokeThickness="1"
                >
                    <Path.Data>
                        <PathGeometry>
                            <PathGeometry.Figures>
                                <PathFigure
                  StartPoint="10,10"
                 >
                                    <PathFigure.Segments>
                                        <LineSegment
                                            x:Name="lineTest"
                    Point="10,100"
                   />
                                        <LineSegment
                    Point="100,100"
                   />
                                        <LineSegment
                    Point="100,10"
                   />
                                        <LineSegment
                    Point="10,10"
                   />
                                    </PathFigure.Segments>
                                </PathFigure>
                            </PathGeometry.Figures>
                        </PathGeometry>
                    </Path.Data>
                    <Path.Triggers>
                        <EventTrigger
                            RoutedEvent="Path.Loaded"
                        >
                            <BeginStoryboard>
                                <Storyboard>
                                    <PointAnimation
                                        Storyboard.TargetName="lineTest"
                                        Storyboard.TargetProperty="Point"
                                        From="10,100"
                   To="10,200"
                   Duration="0:0:5"
                                    />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </Path.Triggers>
                </Path>
            </StackPanel>
        </Grid>
    </UserControl>

    2008年11月4日 3:15

全部回复

  • <Canvas Width="400" Height="300">
        <Canvas.Resources>
            <Storyboard x:Name="myStoryboard">
                <PointAnimationUsingKeyFrames
              Storyboard.TargetProperty="Center"
              Storyboard.TargetName="MyAnimatedEllipseGeometry"
              Duration="0:0:5" RepeatBehavior="Forever">
                    <LinearPointKeyFrame KeyTime="0:0:0.5" Value="100,300" />
                    <DiscretePointKeyFrame KeyTime="0:0:1" Value="400,300" />
                    <SplinePointKeyFrame KeySpline="0.6,0.0 0.9,0.00"
                     KeyTime="0:0:3" Value="200,100" />
                </PointAnimationUsingKeyFrames>
            </Storyboard>
        </Canvas.Resources>
        <Path Fill="Blue" Loaded="Start_Animation">
            <Path.Data>
                <EllipseGeometry x:Name="MyAnimatedEllipseGeometry"
                 Center="200,100" RadiusX="15" RadiusY="15" />
            </Path.Data>
        </Path>
    </Canvas>

    2008年11月4日 2:31
    版主
  • C#让动画开始运动的代码

    Code Snippet
    private void Start_Animation(object sender, EventArgs e)
    {
        myStoryboard.Begin();
    }

     

     

     

     

    2008年11月4日 2:43
    版主
  • 我想楼主要把思路改一下,当我看到你的贴时做测试也做了一段时间,突然想明白了,Polygon的Points集合是没法加动画的,Polygon只是为了,做图标……,做动画也无非是整体变化,要是想做形状的变形动画可以用Path,我写了个简单的Demo希望对你有帮助。

     

    <UserControl
        x:Class="SilverlightApplication1.Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >
        <Grid>
            <StackPanel
                Orientation="Vertical"
            >
                <Path
                    Fill="RoyalBlue"
              Stroke="Orange"
              StrokeThickness="1"
                >
                    <Path.Data>
                        <PathGeometry>
                            <PathGeometry.Figures>
                                <PathFigure
                  StartPoint="10,10"
                 >
                                    <PathFigure.Segments>
                                        <LineSegment
                                            x:Name="lineTest"
                    Point="10,100"
                   />
                                        <LineSegment
                    Point="100,100"
                   />
                                        <LineSegment
                    Point="100,10"
                   />
                                        <LineSegment
                    Point="10,10"
                   />
                                    </PathFigure.Segments>
                                </PathFigure>
                            </PathGeometry.Figures>
                        </PathGeometry>
                    </Path.Data>
                    <Path.Triggers>
                        <EventTrigger
                            RoutedEvent="Path.Loaded"
                        >
                            <BeginStoryboard>
                                <Storyboard>
                                    <PointAnimation
                                        Storyboard.TargetName="lineTest"
                                        Storyboard.TargetProperty="Point"
                                        From="10,100"
                   To="10,200"
                   Duration="0:0:5"
                                    />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </Path.Triggers>
                </Path>
            </StackPanel>
        </Grid>
    </UserControl>

    2008年11月4日 3:15
  • 非常感谢,关于路径的应用我还不是很得心应手,好好研究一下,我觉得polygon的形状动画改变还是很有使用前途的,有机会一起研讨一下,看看写出一个控件来用用,非常感谢。
    2008年11月10日 1:56
  • 好呀,我也很喜欢与志同道合的朋友交流

    QQ 14682233     45166608

     

    2008年11月10日 7:32