【问题标题】:Is it possible to change a storyboard's target in the code in windows phone 8?是否可以在 windows phone 8 的代码中更改情节提要的目标?
【发布时间】:2014-01-19 17:59:42
【问题描述】:

我有一个故事板,我想将其应用于单击的 Windows.Shapes.Rectangle。这可能吗?绑定有用吗?

<Storyboard x:Name="TileClick">
    <ColorAnimation Duration="0:0:1" To="Red" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName= "{Binding}" d:IsOptimized="True"/>
</Storyboard>       

【问题讨论】:

  • 请检查答案或向我们添加更多帮助

标签: c# .net windows-phone-8 storyboard windows-store-apps


【解决方案1】:

在为动画配置另一个目标之前,您必须停止实际的动画。
像这样:

 ColorAnimation.Stop();
 Storyboard.SetTarget(ColorAnimation, myRectangle);
 ColorAnimation.Begin();

【讨论】:

    【解决方案2】:

    您应该像这样为 ColorAnimation 命名:

    <ColorAnimation x:Name="Ca" Duration="0:0:1" To="Red" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName= "{Binding}" d:IsOptimized="True"/>
    

    然后,您可以像访问 C# 中的目标数据

    Ca.TargetName = YOURTARGET;
    

    Ca.SetValue(Storyboard.TargetNameProperty, YOURTARGET.Name); 
    

    我还在stackoverflow上找到了另一个答案:Windows Phone - Storyboard TargetName in runtime

    如果其他代码不起作用,还有另一个附加代码

    Storyboard.SetTarget(myDoubleAnimation1, myRectangle);
    

    来源:http://blogs.msdn.com/b/silverlight_sdk/archive/2008/03/24/create-an-animation-in-code.aspx

    【讨论】:

    • 我这样做了,没有 TargetName 属性
    • 对不起,你是对的。你能试试 Ca.SetValue(Storyboard.TargetNameProperty, YOUROBJECT.Name);我在帖子上更改了一些内容,请再次查看。
    • 我收到此错误:System.Windows.ni.dll 中发生“System.InvalidOperationException”类型的异常,但未在用户代码中处理其他信息:操作在活动动画上无效或故事板。必须先停止根 Storyboard。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-16
    • 2013-12-03
    • 2014-01-05
    • 2012-03-22
    • 2010-11-23
    • 2018-09-24
    相关资源
    最近更新 更多