title: Stop WPF animation, storyboard begin in xaml but stopping it in codebehind?
body: <p>I created an animation storyboard in xaml file. That story board begins on Button.Click. But to stop the animation I am trying to stop storyboard on my custom event in code behind. 
  The code is not throwing any exception but When my event got fired the animation still goes continue.</p>
  
  <p>I think the issue is with the Stop method. Stop required the same object that begins the animation to stop it. But here the storyboard is begin in WPF xaml and I am stopping it in code behind.</p>
  
  <p>Any Solution, how to get Xaml object in code behind or Any alternative solution for this??</p>
  
  <p><strong>XAML CODE:</strong></p>
  
  <pre><code>&lt;Canvas.Triggers&gt;
              &lt;EventTrigger RoutedEvent="Button.Click" SourceName="ScanButton"&gt;
                  &lt;EventTrigger.Actions&gt;
                      &lt;BeginStoryboard &gt;
                          &lt;Storyboard  Name="MovingServer" Storyboard.TargetName="ImageMove" RepeatBehavior="Forever" &gt;
                              &lt;DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:2" From="30" To="300" BeginTime="0:0:0" /&gt;
                              &lt;DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:5" From="300" To="300" BeginTime="0:0:5" /&gt;
                              &lt;DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:2" From="300" To="600" BeginTime="0:0:7" /&gt;
                              &lt;DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:2" From="1" To="0" BeginTime="0:0:7" /&gt;
                          &lt;/Storyboard&gt;
                      &lt;/BeginStoryboard&gt;
                  &lt;/EventTrigger.Actions&gt;
              &lt;/EventTrigger&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Code Behind:</strong></p>
  
  <pre><code>    private void EventPublisher_OnScanningFinish(object sender, EventArgs args)
      {
          Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { this.StopScanningAnimation(); });
      }
  
      private void StopScanningAnimation()
      {
  
          ServerView.StoryBoardServerScrolling.Stop(this); //---------- Not Working
  
          //this.ServerView.Server1Static.Visibility = System.Windows.Visibility.Hidden;
          //this.ServerView.Server2Static.Visibility = System.Windows.Visibility.Hidden;
          //this.ServerView.Server3Scrolling.Visibility = System.Windows.Visibility.Hidden;
          //this.ServerView.SearchingGlass.Visibility = System.Windows.Visibility.Hidden;
      }
  </code></pre>