views:

181

answers:

1

I want to translate an object on its Y-axis over time in Silverlight, but its height is not constant, so I'd like to be able to change the second line of the following from:

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
    <EasingDoubleKeyFrame KeyTime="00:00:00"  Value="-50"/>
    <EasingDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>

to something more like:

<EasingDoubleKeyFrame KeyTime="00:00:00"  Value="-100%"/>

or possibly:

<EasingDoubleKeyFrame KeyTime="00:00:00"  Value="-{ExpandSite Height}"/>

That doesn't compile, however. I'd appreciate any help. I'm using Expression Blend 3, for reference.

EDIT

I basically want to achieve an effect similar to what's demonstrated here, but this code takes for granted that all the objects being translated are 100x100.

A: 

This article describes that the keyframe element does not inherit from the framework element. Because of that you cannot databind to its properties and will have to do the changes in the code behind.

You can find an example of how to create code-behind animations here. However, just note that there is an error in the sample code. The code is missing a line like dd.KeyFrames.Add(easy). On the other hand, you can most probably access the animation if you give it an x:Name and just reference the array elements ( animation.children[0].KeyFrames[0].Value might work)

EDIT I found another thread on this site that does provide a possible work around for what you are trying to do, however I have not tried it myself.

Johannes
How would I access the code behind a control I didn't create, but which I'm modifying via its template?
Dov
From what I've read, Silverlight 4 will have this restriction lifted and you will be able to use databinding for non-framework element objects, so modifying in template without code-behind in this case is not possible.
Krof Drakula