Silverlight 如何通过代码动态创建翻译/移动故事板?

Silverlight 如何通过代码动态创建翻译/移动故事板?,silverlight,windows-phone-7.1,windows-phone-7,Silverlight,Windows Phone 7.1,Windows Phone 7,我正在尝试用代码创建以下情节提要: <Storyboard x:Name="m_activateIdentityStoryboard"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty= "(UIElement.RenderTransform).(CompositeTransform.TranslateY)"

我正在尝试用代码创建以下情节提要:

<Storyboard x:Name="m_activateIdentityStoryboard">
        <DoubleAnimationUsingKeyFrames 
            Storyboard.TargetProperty=
                  "(UIElement.RenderTransform).(CompositeTransform.TranslateY)" 
            Storyboard.TargetName="image">
            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-22"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
但它什么也没做。我很确定我指定了错误的PropertyPath,但我不知道应该在其中放什么,甚至不知道应该如何研究应该放什么。我也不明白“(UIElement.RenderTransform)。(CompositeTransform.TranslateY)”是什么意思,以及如何将其翻译成c

谢谢! 猪

动画的正确c#代码应该是这样的

    // initialize a new instance of the CompositeTransform which allows you 
    // apply multiple different transforms to your image
    this.image.RenderTransform = new CompositeTransform();

    // create the timeline
    var animation = new DoubleAnimationUsingKeyFrames();
    // add key frames to the timeline
    animation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 0 });
    animation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromMilliseconds(200), Value = -22 });
    // notice the first parameter takes a timeline object not the storyboard itself
    Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)"));
    Storyboard.SetTarget(animation, image);

    // create the storyboard
    var storyboard = new Storyboard() { RepeatBehavior = RepeatBehavior.Forever };
    // add the timeline to your storyboard
    storyboard.Children.Add(animation);

    // start the annimation
    storyboard.Begin();

我已经发表了一些评论,希望它们对您有意义。:)

现在,我如何防止图像被剪切到它正在移动的面板的边界?
    // initialize a new instance of the CompositeTransform which allows you 
    // apply multiple different transforms to your image
    this.image.RenderTransform = new CompositeTransform();

    // create the timeline
    var animation = new DoubleAnimationUsingKeyFrames();
    // add key frames to the timeline
    animation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.Zero, Value = 0 });
    animation.KeyFrames.Add(new EasingDoubleKeyFrame { KeyTime = TimeSpan.FromMilliseconds(200), Value = -22 });
    // notice the first parameter takes a timeline object not the storyboard itself
    Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)"));
    Storyboard.SetTarget(animation, image);

    // create the storyboard
    var storyboard = new Storyboard() { RepeatBehavior = RepeatBehavior.Forever };
    // add the timeline to your storyboard
    storyboard.Children.Add(animation);

    // start the annimation
    storyboard.Begin();