2017-09-19 1 views
0

bevor ich diese Frage gestellt habe, habe ich danach gesucht, aber mein Fall ist anders. Ich habe einen Namen Storyboard in Usercontrol wie folgt aus:Bindung Storyboard in Usercontrol zu Storyboard-Objekt in Viewmodel

<Storyboard x:Key="Storyboard1" > 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="rectangle"> 
       <EasingDoubleKeyFrame KeyTime="0:0:2" Value="180"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:4" Value="360"/> 
      </DoubleAnimationUsingKeyFrames> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="smartphone_png"> 
       <SplineDoubleKeyFrame KeyTime="0:0:1.6" Value="205.5"/> 
       <SplineDoubleKeyFrame KeyTime="0:0:2.2" Value="205.5"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:4" Value="466.667"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:5" Value="466.667"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:6" Value="632.334"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:7" Value="706.001"/> 
      </DoubleAnimationUsingKeyFrames> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="smartphone_png"> 
       <EasingDoubleKeyFrame KeyTime="0:0:6" Value="0"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:7" Value="53.333"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:8" Value="196.166"/> 
      </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

und in Ansichtsmodell für diese Usercontrol, ich habe so etwas wie dies für die Bindung an Storyboard1 Storyboard:

Storyboard BoardControl = new Storyboard(); 

var resource =?? \\this line is what I need to bind to Storyboard1 

BoardControl = resource as Storyboard; 
BoardControl.Stop(); 

ich versucht habe:

Objekt Ressource = Application.Current.TryFindResource ("Storyboard1");

es war falsch, weil es scheint, als ob es ein neues Storyboard1-Objekt initialisiert, es war nicht das gleiche Objekt wie der Anfang.

Irgendeine Idee für mich, danke im Voraus.

+0

Warum Sie zu erstellen oder ein Storyboard in Ihrer Ansicht nach Modell versuchen zu benutzen? Storyboards gehören zur Ansicht. – mm8

Antwort

0

Sie kontrollieren nicht noch Zugriff auf eine Storyboard aus einer Ansicht Modellklasse.

Wenn Sie programmatisch die Storyboard zu steuern, sollten Sie dies aus dem Code-behind der Ansicht tun. Sie können dann auf den Storyboard Ressource wie folgt aus:

Storyboard sb = this.Resources["Storyboard1"] as Storyboard; 
+0

Hast du meine Antwort gelesen? Sie sollten dies nicht im View-Modell tun. – mm8

+0

Sie könnten das Storyboard in App.xaml platzieren und mit Application.Current.Resources ["Storyboard1"] darauf zugreifen, aber das ist nicht MVVM. – mm8

+0

für Ihre Frage, ich möchte es verwenden, um den Fluss von Storyboard zu steuern, es bedeutet, dass ich in der Lage bin zu stoppen, zu pausieren, ... das Storyboard. führen Sie es nicht nur durch Klick-Ereignis von Anfang bis Ende. –

Verwandte Themen