Skip to content

Commit

Permalink
Merge pull request #76 from thomaslevesque/fix-resume-on-show
Browse files Browse the repository at this point in the history
Don't resume on show if animation was paused
  • Loading branch information
thomaslevesque authored Mar 8, 2020
2 parents 3672cd6 + 9aed565 commit 510aba1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
32 changes: 27 additions & 5 deletions WpfAnimatedGif/ImageAnimationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal ImageAnimationController(Image image, ObjectAnimationUsingKeyFrames ani

_image.ApplyAnimationClock(Image.SourceProperty, _clock);

IsPaused = !autoStart;
if (autoStart)
_clockController.Resume();
}
Expand Down Expand Up @@ -75,10 +76,7 @@ public TimeSpan Duration
/// <summary>
/// Returns a value that indicates whether the animation is paused.
/// </summary>
public bool IsPaused
{
get { return _clock.IsPaused; }
}
public bool IsPaused { get; private set; }

/// <summary>
/// Returns a value that indicates whether the animation is complete.
Expand Down Expand Up @@ -122,6 +120,7 @@ public int CurrentFrame
/// </summary>
public void Pause()
{
IsPaused = true;
_clockController.Pause();
}

Expand All @@ -130,7 +129,30 @@ public void Pause()
/// </summary>
public void Play()
{
_clockController.Resume();
IsPaused = false;
if (!_isSuspended)
_clockController.Resume();
}

private bool _isSuspended;
internal void SetSuspended(bool isSuspended)
{
if (isSuspended == _isSuspended)
return;

bool wasSuspended = _isSuspended;
_isSuspended = isSuspended;
if (wasSuspended)
{
if (!IsPaused)
{
_clockController.Resume();
}
}
else
{
_clockController.Pause();
}
}

/// <summary>
Expand Down
9 changes: 2 additions & 7 deletions WpfAnimatedGif/ImageBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,8 @@ private static void VisibilityChanged(object sender, DependencyPropertyChangedEv
var controller = GetAnimationController(img);
if (controller != null)
{
if ((bool)e.NewValue)
{
controller.GotoFrame(0);
controller.Play();
}
else
controller.Pause();
bool isVisible = (bool)e.NewValue;
controller.SetSuspended(!isVisible);
}
}
}
Expand Down

0 comments on commit 510aba1

Please sign in to comment.