Skip to content

Commit

Permalink
Merge pull request #1664 from MahApps/punker76-MetroProgressBar-Anima…
Browse files Browse the repository at this point in the history
…tionWarning

Fix MetroProgressBar System.Windows.Media.Animation Warning 6
  • Loading branch information
punker76 committed Nov 22, 2014
2 parents 51caf46 + 5295061 commit 30a5748
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 119 deletions.
22 changes: 12 additions & 10 deletions MahApps.Metro/Controls/MetroProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class MetroProgressBar : ProgressBar
public static readonly DependencyProperty EllipseOffsetProperty =
DependencyProperty.Register("EllipseOffset", typeof(double), typeof(MetroProgressBar),
new PropertyMetadata(default(double)));


private Storyboard indeterminateStoryboard;

static MetroProgressBar()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MetroProgressBar), new FrameworkPropertyMetadata(typeof(MetroProgressBar)));
Expand Down Expand Up @@ -51,14 +53,11 @@ private static void OnIsIndeterminateChanged(DependencyObject dependencyObject,
var containingObject = bar.GetTemplateChild("ContainingGrid") as FrameworkElement;
if (indeterminateState != null && containingObject != null)
{
if ((bool)e.NewValue)
{
indeterminateState.Storyboard.Begin(containingObject, true);
}
else
if (indeterminateState.Storyboard != null)
{
indeterminateState.Storyboard.Stop(containingObject);
}
bar.ResetStoryboard(bar.ActualWidth);
}
}
}
Expand Down Expand Up @@ -105,9 +104,9 @@ private void ResetStoryboard(double width)
{
VisualState indeterminate = GetIndeterminate();

if (indeterminate != null)
if (indeterminate != null && this.indeterminateStoryboard != null)
{
Storyboard newStoryboard = indeterminate.Storyboard.Clone();
Storyboard newStoryboard = this.indeterminateStoryboard.Clone();
Timeline doubleAnim = newStoryboard.Children.First(t => t.Name == "MainDoubleAnim");
doubleAnim.SetValue(DoubleAnimation.FromProperty, containerAnimStart);
doubleAnim.SetValue(DoubleAnimation.ToProperty, containerAnimEnd);
Expand Down Expand Up @@ -141,15 +140,17 @@ private void ResetStoryboard(double width)
doubleAnimParent.InvalidateProperty(Storyboard.TargetNameProperty);
}

indeterminate.Storyboard.Remove();
indeterminate.Storyboard = newStoryboard;

if (!IsIndeterminate)
{
return;
}

indeterminate.Storyboard.Begin((FrameworkElement)GetTemplateChild("ContainingGrid"), true);
if (indeterminate.Storyboard != null)
{
indeterminate.Storyboard.Begin((FrameworkElement)GetTemplateChild("ContainingGrid"), true);
}
}
}
catch (Exception)
Expand Down Expand Up @@ -242,6 +243,7 @@ private double CalcEllipseAnimEnd(double width)
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
indeterminateStoryboard = this.TryFindResource("IndeterminateStoryboard") as Storyboard;
SizeChangedHandler(null, null);
}

Expand Down
Loading

0 comments on commit 30a5748

Please # to comment.