自定义故事板中的“无法解析TargetName”错误

时间:2012-01-16 14:44:17

标签: windows-phone-7 animation storyboard

在WP7 silverlight应用程序中,我想在特定事件中使用故事板动画。 动画正在将按钮高度属性从x更改为y点(为查询而更改)。

我在我的程序中使用以下代码

   Storyboard myStoryBoard = new Storyboard();
   myStoryBoard.Duration = new Duration(TimeSpan.FromMilliseconds(200));

   DoubleAnimation myDoubleAnimation = new DoubleAnimation();
   Storyboard.SetTargetName(myDoubleAnimation, button1.Name); // button1 is normal button on UI
   Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Button.HeightProperty));

   myDoubleAnimation.From = 200;
   myDoubleAnimation.To = 300;

   myStoryBoard.Children.Add(myDoubleAnimation);
   myStoryBoard.Begin();

当我运行我的代码时,我正在努力      无法解析TargetName button1 错误

对我的问题有什么简单的解决方法吗?

1 个答案:

答案 0 :(得分:5)

我认为只有在Storyboard位于可视化树中时才能使用SetTargetName。我建议改用SetTarget:http://msdn.microsoft.com/en-us/library/system.windows.media.animation.storyboard.settarget%28v=vs.95%29.aspx

Storyboard.SetTarget(myDoubleAnimation, button1);
相关问题