Пример #1
0
        /// <summary>
        /// Radius changed.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void RadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PulseButton pb = (PulseButton)d;

            if (pb == null || pb.partPulseContainer == null)
            {
                return;
            }
            if (!pb.IsEllipsis)
            {
                PulsesChanged(d, e);
            }
        }
Пример #2
0
        /// <summary>
        /// Determines whether IsPulsing changed.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void IsPulsingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PulseButton pb = (PulseButton)d;

            if (pb == null || pb.partPulseContainer == null)
            {
                return;
            }
            if (!pb.IsPulsing)
            {
                pb.partPulseContainer.Children.Clear();
            }
            else
            {
                PulsesChanged(d, e);
            }
        }
Пример #3
0
        /// <summary>
        /// Pulses changed.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void PulsesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PulseButton pb = (PulseButton)d;

            if (pb == null || pb.partPulseContainer == null || !pb.IsPulsing)
            {
                return;
            }
            // Clear all pulses
            pb.partPulseContainer.Children.Clear();
            int items = pb.Pulses;

            // Add pulses
            for (int i = 0; i < items; i++)
            {
                Shape shape = pb.IsEllipsis ?
                              (Shape) new Ellipse
                {
                    StrokeThickness       = pb.PulseWidth,
                    Stroke                = pb.PulseColor,
                    RenderTransformOrigin = new Point(0.5, 0.5),
                    IsHitTestVisible      = false
                } :
                new Rectangle
                {
                    RadiusX               = pb.RadiusX,
                    RadiusY               = pb.RadiusY,
                    StrokeThickness       = pb.PulseWidth,
                    Stroke                = pb.PulseColor,
                    RenderTransformOrigin = new Point(0.5, 0.5),
                    IsHitTestVisible      = false
                };
                pb.partPulseContainer.Children.Add(shape);
            }
            // Set animations
            pb.SetStoryBoard(pb);
        }
Пример #4
0
        /// <summary>
        /// Sets the story board for the pulses
        /// </summary>
        /// <param name="pb">The pb.</param>
        private void SetStoryBoard(PulseButton pb)
        {
            double delay = 0;

            // Correct PulseScale according to control dimensions
            double correctedFactorX = pb.PulseScale, correctedFactorY = pb.PulseScale;

            if (pb.IsMeasureValid)
            {
                if (pb.ActualHeight < pb.ActualWidth)
                {
                    correctedFactorY = (pb.PulseScale - 1) * ((pb.ActualWidth - pb.ActualHeight) / (1 + pb.ActualHeight)) + pb.PulseScale;
                }
                else
                {
                    correctedFactorX = (pb.PulseScale - 1) * ((pb.ActualHeight - pb.ActualWidth) / (1 + pb.ActualWidth)) + pb.PulseScale;
                }
            }
            // Add pulses
            foreach (Shape shape in pb.partPulseContainer.Children)
            {
                shape.RenderTransform = new ScaleTransform();
                // X-axis animation
                DoubleAnimation animation = new DoubleAnimation(1, correctedFactorX, pb.PulseSpeed)
                {
                    RepeatBehavior = RepeatBehavior.Forever,
                    AutoReverse    = false,
                    BeginTime      = TimeSpan.FromMilliseconds(delay),
                    EasingFunction = pb.PulseEasing
                };
                // Y-axis animation
                DoubleAnimation animation2 = new DoubleAnimation(1, correctedFactorY, pb.PulseSpeed)
                {
                    RepeatBehavior = RepeatBehavior.Forever,
                    AutoReverse    = false,
                    BeginTime      = TimeSpan.FromMilliseconds(delay),
                    EasingFunction = pb.PulseEasing
                };
                // Opacity animation
                DoubleAnimation animation3 = new DoubleAnimation(1, 0, pb.PulseSpeed)
                {
                    RepeatBehavior = RepeatBehavior.Forever,
                    AutoReverse    = false,
                    BeginTime      = TimeSpan.FromMilliseconds(delay)
                };
                // Set delay between pulses
                delay += pb.PulseSpeed.TimeSpan.TotalMilliseconds / pb.Pulses;
                // Create storyboard
                Storyboard storyboard = new Storyboard();
                storyboard.Children.Add(animation);
                storyboard.Children.Add(animation2);
                storyboard.Children.Add(animation3);
                Storyboard.SetTarget(animation, shape);
                Storyboard.SetTarget(animation2, shape);
                Storyboard.SetTarget(animation3, shape);
                if (pb.IsEllipsis)
                {
                    Storyboard.SetTargetProperty(animation, new PropertyPath("(Ellipse.RenderTransform).(ScaleTransform.ScaleX)"));
                    Storyboard.SetTargetProperty(animation2, new PropertyPath("(Ellipse.RenderTransform).(ScaleTransform.ScaleY)"));
                    Storyboard.SetTargetProperty(animation3, new PropertyPath("(Ellipse.Opacity)"));
                }
                else
                {
                    Storyboard.SetTargetProperty(animation, new PropertyPath("(Rectangle.RenderTransform).(ScaleTransform.ScaleX)"));
                    Storyboard.SetTargetProperty(animation2, new PropertyPath("(Rectangle.RenderTransform).(ScaleTransform.ScaleY)"));
                    Storyboard.SetTargetProperty(animation3, new PropertyPath("(Rectangle.Opacity)"));
                }
                // Start storyboard
                storyboard.Begin();
            }

            #endregion
        }