diff --git a/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Media/ControlStoryboardAction.cs b/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Media/ControlStoryboardAction.cs index 6c1035ca..2d64f2b6 100644 --- a/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Media/ControlStoryboardAction.cs +++ b/src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions/Media/ControlStoryboardAction.cs @@ -2,139 +2,140 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. namespace Microsoft.Xaml.Interactions.Media { - using Interactivity; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Media.Animation; - - /// - /// An action that will change the state of the specified when executed. - /// - public sealed class ControlStoryboardAction : DependencyObject, IAction - { - /// - /// Identifies the dependency property. - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] - public static readonly DependencyProperty ControlStoryboardOptionProperty = DependencyProperty.Register( - "ControlStoryboardOption", - typeof(ControlStoryboardOption), - typeof(ControlStoryboardAction), - new PropertyMetadata(ControlStoryboardOption.Play)); - - /// - /// Identifies the dependency property. - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] - public static readonly DependencyProperty StoryboardProperty = DependencyProperty.Register( - "Storyboard", - typeof(Storyboard), - typeof(ControlStoryboardAction), - new PropertyMetadata(null, new PropertyChangedCallback(ControlStoryboardAction.OnStoryboardChanged))); - - private bool _isPaused; - - /// - /// Gets or sets the action to execute on the . This is a dependency property. - /// - public ControlStoryboardOption ControlStoryboardOption - { - get - { - return (ControlStoryboardOption)this.GetValue(ControlStoryboardAction.ControlStoryboardOptionProperty); - } - set - { - this.SetValue(ControlStoryboardAction.ControlStoryboardOptionProperty, value); - } - } - - /// - /// Gets or sets the targeted . This is a dependency property. - /// - public Storyboard Storyboard - { - get - { - return (Storyboard)this.GetValue(ControlStoryboardAction.StoryboardProperty); - } - set - { - this.SetValue(ControlStoryboardAction.StoryboardProperty, value); - } - } - - /// - /// Executes the action. - /// - /// The that is passed to the action by the behavior. Generally this is or a target object. - /// The value of this parameter is determined by the caller. - /// True if the specified operation is invoked successfully; else false. - public object Execute(object sender, object parameter) - { - if (this.Storyboard == null) - { - return false; - } - - switch (this.ControlStoryboardOption) - { - case ControlStoryboardOption.Play: - this.Storyboard.Begin(); - break; - - case ControlStoryboardOption.Stop: - this.Storyboard.Stop(); - break; - - case ControlStoryboardOption.TogglePlayPause: - { - ClockState currentState = this.Storyboard.GetCurrentState(); - - if (currentState == ClockState.Stopped) - { - this._isPaused = false; - this.Storyboard.Begin(); - } - else if (this._isPaused) - { - this._isPaused = false; - this.Storyboard.Resume(); - } - else - { - this._isPaused = true; - this.Storyboard.Pause(); - } - } - - break; - - case ControlStoryboardOption.Pause: - this.Storyboard.Pause(); - break; - - case ControlStoryboardOption.Resume: - this.Storyboard.Resume(); - break; - - case ControlStoryboardOption.SkipToFill: - this.Storyboard.SkipToFill(); - break; - - default: - return false; - } - - return true; - } - - private static void OnStoryboardChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) - { - ControlStoryboardAction action = sender as ControlStoryboardAction; - if (action != null) - { - action._isPaused = false; - } - } - } + using Interactivity; + using Windows.UI.Xaml; + using Windows.UI.Xaml.Media.Animation; + + /// + /// An action that will change the state of the specified when executed. + /// + public sealed class ControlStoryboardAction : DependencyObject, IAction + { + /// + /// Identifies the dependency property. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] + public static readonly DependencyProperty ControlStoryboardOptionProperty = DependencyProperty.Register( + "ControlStoryboardOption", + typeof(ControlStoryboardOption), + typeof(ControlStoryboardAction), + new PropertyMetadata(ControlStoryboardOption.Play)); + + /// + /// Identifies the dependency property. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] + public static readonly DependencyProperty StoryboardProperty = DependencyProperty.Register( + "Storyboard", + typeof(Storyboard), + typeof(ControlStoryboardAction), + new PropertyMetadata(null)); + + public static readonly DependencyProperty IsPausedProperty = DependencyProperty.RegisterAttached("IsPaused", typeof(bool), typeof(Storyboard), new PropertyMetadata(false)); + + public static void SetIsPaused(Storyboard obj, bool value) + { + obj.SetValue(IsPausedProperty, value); + } + + public static bool GetIsPaused(Storyboard obj) + { + return (bool)obj.GetValue(IsPausedProperty); + } + + /// + /// Gets or sets the action to execute on the . This is a dependency property. + /// + public ControlStoryboardOption ControlStoryboardOption + { + get + { + return (ControlStoryboardOption)this.GetValue(ControlStoryboardAction.ControlStoryboardOptionProperty); + } + set + { + this.SetValue(ControlStoryboardAction.ControlStoryboardOptionProperty, value); + } + } + + /// + /// Gets or sets the targeted . This is a dependency property. + /// + public Storyboard Storyboard + { + get + { + return (Storyboard)this.GetValue(ControlStoryboardAction.StoryboardProperty); + } + set + { + this.SetValue(ControlStoryboardAction.StoryboardProperty, value); + } + } + + /// + /// Executes the action. + /// + /// The that is passed to the action by the behavior. Generally this is or a target object. + /// The value of this parameter is determined by the caller. + /// True if the specified operation is invoked successfully; else false. + public object Execute(object sender, object parameter) + { + if (this.Storyboard == null) + { + return false; + } + + switch (this.ControlStoryboardOption) + { + case ControlStoryboardOption.Play: + this.Storyboard.Begin(); + break; + + case ControlStoryboardOption.Stop: + this.Storyboard.Stop(); + break; + + case ControlStoryboardOption.TogglePlayPause: + { + ClockState currentState = this.Storyboard.GetCurrentState(); + + if (currentState == ClockState.Stopped) + { + SetIsPaused(this.Storyboard, false); + this.Storyboard.Begin(); + } + else if (GetIsPaused(this.Storyboard)) + { + SetIsPaused(this.Storyboard, false); + this.Storyboard.Resume(); + } + else + { + SetIsPaused(this.Storyboard, true); + this.Storyboard.Pause(); + } + } + + break; + + case ControlStoryboardOption.Pause: + this.Storyboard.Pause(); + break; + + case ControlStoryboardOption.Resume: + this.Storyboard.Resume(); + break; + + case ControlStoryboardOption.SkipToFill: + this.Storyboard.SkipToFill(); + break; + + default: + return false; + } + + return true; + } + } }