我试图在后面的代码中创建它。但它抛出“参数不正确”的例外。
<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>
代码背后的代码是:
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);
它在最后一段代码中抛出错误。
答案 0 :(得分:2)
我已经改变了
Storyboard.SetTarget(anim, aceSpades.Projection);
到
Storyboard.SetTargetName(anim, "aceSpades");
它有效。