charri / Font-Awesome-WPF

FontAwesome controls for WPF+UWP
MIT License
533 stars 145 forks source link

Changable Duration for Spinning Icons #17

Closed punker76 closed 9 years ago

punker76 commented 9 years ago

Add an attached dependency property to set the spinning animation duration.

This Fixes #16 Changable Duration for Spinning Icons

punker76 commented 9 years ago

@charri this property can maybe directly implemented for the ISpinnable interface. what do you think?

punker76 commented 9 years ago

@charri busy or is this repo dead?

TrabacchinLuigi commented 9 years ago

@punker76 i hope not!

charri commented 9 years ago

@punker76 - Sorry for the delay, currently very busy: busy

I will look at the pull-request asap :), thanks for being so patient

punker76 commented 9 years ago

@charri will do that now.

one thing

this property can maybe directly implemented for the ISpinnable interface. what do you think?

charri commented 9 years ago

not sure i understand the question. how can you implement the property in the ISpinnable interface?

punker76 commented 9 years ago

@charri i mean, this attached property can be implemented directly as dependency property in FontAwesome and ImageAwesome (ok its a little bit boilerplate code)

    public interface ISpinable
    {
        /// <summary>
        /// Gets or sets the current spin (angle) animation of the icon.
        /// </summary>
        bool Spin { get; set; }

        /// <summary>
        /// Gets/Sets the duration of the spinning animation (in seconds). This will stop and start the spin animation.
        /// </summary>
        double SpinDuration { get; set; }
    }
charri commented 9 years ago

good idea, then it can be directly accessed as a property in the FontAwesome class

punker76 commented 9 years ago

@charri this one...

        /// <summary>
        /// Identifies the FontAwesome.WPF.ImageAwesome.Spin dependency property.
        /// </summary>
        public static readonly DependencyProperty SpinDurationProperty =
            DependencyProperty.Register("SpinDuration", typeof(double), typeof(ImageAwesome), new PropertyMetadata(1d, SpinDurationChanged, SpinDurationCoerceValue));

        /// <summary>
        /// Gets or sets the duration of the spinning animation (in seconds). This will stop and start the spin animation.
        /// </summary>
        public double SpinDuration
        {
            get { return (double)GetValue(SpinProperty); }
            set { SetValue(SpinProperty, value); }
        }

        private static void SpinDurationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var imageAwesome = d as ImageAwesome;

            if (null == imageAwesome || !imageAwesome.Spin || !(e.NewValue is double) || e.NewValue.Equals(e.OldValue)) return;

            imageAwesome.StopSpin();
            imageAwesome.BeginSpin();
        }
charri commented 9 years ago

:+1:

punker76 commented 9 years ago

@charri done

charri commented 9 years ago

that was fast!

I will do nuget push tomorrow/friday.