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

Mah*_*der 4 animation storyboard windows-phone-7

在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();
Run Code Online (Sandbox Code Playgroud)

当我运行我的代码,我打 不到解决TargetName button1错误

我的问题可以轻松解决吗?

Kev*_*sse 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);
Run Code Online (Sandbox Code Playgroud)