2012-12-06 41 views
1

我不确定这里发生了什么。我遵循Microsoft提供的示例。一切都是在后端完成的,因为我需要决定用户是否应该将东西输入到文本字段中,或者应该将文本字段值显示为普通文本。代码如下:Storyboard.begin()抛出一个InvalidOperationException

  nameInput.Name = "inputName"; 
      nameInput.Text = "Journey Name"; 
      nameInput.KeyUp += onNameInput; 

      ColorAnimation animation = new ColorAnimation(); 
      animation.From = Colors.Blue; 
      animation.To = Colors.White; 
      animation.Duration = new Duration(TimeSpan.FromMilliseconds(100)); 
      animation.RepeatBehavior = RepeatBehavior.Forever; 
      Storyboard.SetTarget(animation, nameInput); 
      Storyboard.SetTargetProperty(animation, new PropertyPath(TextBlock.ForegroundProperty)); 
      storyBoard.Children.Add(animation); 
      journeyStackPanel.Children.Add(nameInput); 
      ClockState state = storyBoard.GetCurrentState(); 
      storyBoard.Begin(); //<---Crashes here 

我下面的

http://msdn.microsoft.com/en-us/library/cc672995(v=vs.95).aspx 

例子。我不确定发生了什么,不幸的是调试器不会吐出更多的信息。也许我错过了一步?对不起,我有点模糊,但这是我在这个问题上的所有信息。

任何帮助非常感谢!

回答

2

我能复制这个问题上的最新WP8 SDK,以生成以下错误信息:

ColorAnimation不能用于动画属性前景由于 不兼容的类型。

我相信这是因为您试图将TextBox的Foreground属性更改为Color对象,但Foreground实际上是一个Brush对象,因此类型不匹配错误。相反,您必须更改Foreground对象的Color属性。

试试这个:

Storyboard.SetTargetProperty(animation, new PropertyPath("(Foreground).(Color)"));

相关问题