tags:

views:

39

answers:

3

Hi All,

I am using some animation on my user control code behind.

double height = canMain.ActualHeight - marqueeList.ActualHeight;
        marqueeList.Margin = new Thickness(0, height / 2, 0, 0);
        DoubleAnimation doubleAnimation = new DoubleAnimation();
        doubleAnimation.From = -marqueeList.ActualWidth;
        doubleAnimation.To = canMain.ActualWidth;
        doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
        doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(_marqueeTimeInSeconds));
        marqueeList.BeginAnimation(Canvas.RightProperty, doubleAnimation);

I want when i put my mouse on user control the animation should stop. Can any body help me on this its urgent ...!

+1  A: 

You can handle the MouseMove event and check the IsMouseOver property

Thomas Levesque
thanks for ur reply !! i updated my question now my code is also there can u please tell me how can i stop animation.iam using the above code for start animation and now i want to stop can you please help me on this according to above code
ashish semwal
+1  A: 

You should be able to use the Storyboard.Stop() method if you have started the animation setting the isControllable to true

Storyboard.Begin(this, true); 

you also have the Storyboard.Pause() method if you plan to restart it again on some condition.

Take a look at this: http://msdn.microsoft.com/en-us/library/ms742868.aspx

Try this too:

<Style.Triggers>
    <Trigger Property="IsMouseOver" Value="False">
      <Trigger.EnterActions>
        <BeginStoryboard>
          <Storyboard>
            <!-- do your animation here (forever) -->
          </Storyboard>
        </BeginStoryboard>
      </Trigger.EnterActions>
      <Trigger.ExitActions>
        <BeginStoryboard>
          <Storyboard>
            <!-- fake animation with duration set to 0 -->
          </Storyboard>
        </BeginStoryboard>
      </Trigger.ExitActions>          
    </Trigger>               
  </Style.Triggers>   
Veer
A: 

Thanks for your replies!!

I found my answer, I used mouse enter and mouse leave events for this.

On mouse enter :

  Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Right)"));
            _storyBoard.Children.Add(doubleAnimation);
            _storyBoard.Pause(marqueeList);

On mouse leave :

    Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Right)"));
        _storyBoard.Children.Add(doubleAnimation);
        _storyBoard.Resume(marqueeList);
ashish semwal