2009-03-30 10 views
4

J'ai un cube 3D que j'anime en utilisant un storyboard partagé. Le code d'animation se trouve dans l'événement selectionChanged d'une liste déroulante et a pour but de s'assurer que toute animation en cours d'exécution soit arrêtée avant le début de la suivante; mais ça ne marche pas comme ça!WPF - Impossible d'arrêter une animation StoryBoard, IsControllable ne fonctionne pas?

Je me rends compte que c'est un code assez désordonné mais je ne vois toujours pas pourquoi mon storyboard ne répondra pas au contrôle depuis que j'appelle .begin (ceci, vrai). Quelqu'un peut-il me dire pourquoi je ne peux pas arrêter le StoryBoard? Je suis toujours obtenir que louches 'System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='Stop';' un message

 Storyboard sb = new Storyboard(); 
    DoubleAnimation forward90 = new DoubleAnimation(0,90,TimeSpan.FromMilliseconds(2000)); 
    DoubleAnimation back90 = new DoubleAnimation(0,-90, TimeSpan.FromMilliseconds(2000)); 

private void cbo_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     forward90.BeginTime = TimeSpan.Zero; 
     back90.BeginTime = TimeSpan.Zero; 

     NameScope.SetNameScope(this, new NameScope()); 

     RegisterName(this.Name, this); 

     sb.Stop(this); 
     sb.Remove(this); 

     sb.Children.Clear(); 

     sb.AccelerationRatio = 0; 
     sb.DecelerationRatio = 1; 
     sb.RepeatBehavior = RepeatBehavior.Forever; 

     int i = cbo.SelectedIndex; 
     Orientation o = (Orientation)i; 

     ViewModel vm = this.DataContext as ViewModel; 
     if(vm !=null)vm.Orient = o; 


     switch (o) 
     { 
      case Orientation.Front0: 

       break; 
      case Orientation.Front90: 

       sb.Children.Add(forward90); 

       Storyboard.SetTarget(forward90, cube2); 

       Storyboard.SetTargetProperty(forward90, new PropertyPath(CubeControl.CubeControl.XRotationProperty)); 
       sb.Begin(this, true); 

       break; 
      case Orientation.Right0: 

       sb.Children.Add(back90); 

       Storyboard.SetTarget(back90, cube2); 

       Storyboard.SetTargetProperty(back90, new PropertyPath(CubeControl.CubeControl.YRotationProperty)); 
       sb.Begin(this, true); 

       break; 
      case Orientation.Right90: 

       back90.BeginTime = TimeSpan.FromMilliseconds(2000); 

       sb.Children.Add(forward90); 
       sb.Children.Add(back90); 

       Storyboard.SetTarget(back90, cube2); 
       Storyboard.SetTarget(forward90, cube2); 

       Storyboard.SetTargetProperty(forward90, new PropertyPath(CubeControl.CubeControl.YRotationProperty)); 
       Storyboard.SetTargetProperty(back90, new PropertyPath(CubeControl.CubeControl.ZRotationProperty)); 

       sb.Begin(this, true); 

       break; 
      case Orientation.Top0: 

       sb.Children.Add(back90); 

       Storyboard.SetTarget(back90, cube2); 
       Storyboard.SetTargetProperty(back90, new PropertyPath(CubeControl.CubeControl.ZRotationProperty)); 
       sb.Begin(this, true); 

       break; 
      case Orientation.Top90: 

       back90.BeginTime = TimeSpan.FromMilliseconds(2000); 

       sb.Children.Add(forward90); 
       sb.Children.Add(back90); 

       Storyboard.SetTarget(forward90, cube2); 
       Storyboard.SetTarget(back90, cube2); 

       Storyboard.SetTargetProperty(forward90, new PropertyPath(CubeControl.CubeControl.XRotationProperty)); 
       Storyboard.SetTargetProperty(back90, new PropertyPath(CubeControl.CubeControl.ZRotationProperty)); 

       sb.Begin(this, true); 
       break; 
      default: 
       break; 
     } 
    } 
} 

Répondre

3

Je crois que vous devez passer OBC plutôt que cela dans la méthode commencer.

cela fait référence à la classe actuelle (je suppose que votre classe de fenêtre) alors que c'est le changement dans cbo que c'est de contrôler l'animation.

+0

Pas de dés J'ai peur. Juste essayé mais ça ne marchait toujours pas. Et bien! – Stimul8d

+0

J'ai juste rattrapé quelques vieux billets et j'ai trouvé que vous aviez raison ... J'avais juste besoin de retirer les noms NameScope et RegisterName. – Stimul8d