简体   繁体   中英

Windows Phone - ObjectAnimationUsingKeyFrames in code behind

I am trying to create this in code behind. But it is throwing "The Parameter is incorrect" exception.

<VisualState x:Name="FlipCard" >
    <Storyboard >
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="aceSpades">
            <DiscreteObjectKeyFrame KeyTime="0:0:1">
                <DiscreteObjectKeyFrame.Value>
                    <Visibility>Visible</Visibility>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

Code behind code is:

VisualState vst = (VisualState)FindName("FlipCard");

ObjectAnimationUsingKeyFrames anim = new ObjectAnimationUsingKeyFrames();

DiscreteObjectKeyFrame obj = new DiscreteObjectKeyFrame();

obj.Value = Visibility.Visible;
obj.KeyTime = TimeSpan.FromSeconds(1);
anim.KeyFrames.Add(obj);

Storyboard.SetTarget(anim, aceSpades.Projection);
Storyboard.SetTargetProperty(anim, new PropertyPath(Image.VisibilityProperty));

vst.Storyboard.Children.Add(anim);

VisualStateManager.GoToState(this, "FlipCard", true);

It throwing error in last code.

I have changed

Storyboard.SetTarget(anim, aceSpades.Projection);

to

Storyboard.SetTargetName(anim, "aceSpades");

And it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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