Created
June 24, 2015 10:23
-
-
Save OmerRaviv/3972e8994ac2afc7e55c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyUserControl{ | |
InitializeComponent(); | |
Loaded += delegate { StartAnimating(); }; | |
} | |
public double StrokeValue | |
{ | |
get { return (double)GetValue(StrokeValueProperty); } | |
set { SetValue(StrokeValueProperty, value); } | |
} | |
public static readonly DependencyProperty StrokeValueProperty = | |
DependencyProperty.Register("StrokeValue", typeof(double), typeof(SimplifyJoystick) | |
, new PropertyMetadata(0.0, OnStrokeValueChanged)); | |
private static void OnStrokeValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | |
{ | |
((SimplifyJoystick)d).AnimatedStrokeArray = new DoubleCollection { (double)e.NewValue, 10000 }; | |
} | |
public DoubleCollection AnimatedStrokeArray | |
{ | |
get { return (DoubleCollection)GetValue(AnimatedStrokeArrayProperty); } | |
set { SetValue(AnimatedStrokeArrayProperty, value); } | |
} | |
public static readonly DependencyProperty AnimatedStrokeArrayProperty = | |
DependencyProperty.Register("AnimatedStrokeArray", typeof(DoubleCollection), typeof(SimplifyJoystick) | |
, new PropertyMetadata(new DoubleCollection { 0, 100 })); | |
private void StartAnimating() | |
{ | |
var storyboard = new Storyboard() { RepeatBehavior = RepeatBehavior.Forever}; | |
var animation = new DoubleAnimation(0, ActualHeight * 4, new Duration(TimeSpan.FromSeconds(2))); | |
storyboard.Children.Add(animation); | |
Storyboard.SetTarget(animation, this); | |
Storyboard.SetTargetProperty(animation, new PropertyPath(SimplifyJoystick.StrokeValueProperty)); | |
storyboard.Begin(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment