Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix MetroProgressBar System.Windows.Media.Animation Warning 6 #1664

Merged
merged 2 commits into from
Nov 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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