예제 #1
0
        /// <summary>
        /// Handles the MouseMove event of the FixedBar control. It implements "Carousel" logic.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
        private void FixedBar_MouseMove(object sender, MouseEventArgs e)
        {
            var icon = carousel.Children.OfType <WindowIcon>().FirstOrDefault();

            // If there is at least one icon on the bar
            if (icon != null)
            {
                double a = e.GetPosition(fixedBar).X;
                double b = fixedBar.ActualWidth - fixedBar.Padding.Horizontal();
                double c = slidingBar.ActualWidth;

                // If sliding bar does not fit into the bar, shift the sliding bar
                if (c > b)
                {
                    double width = b - icon.ActualWidth;
                    if (width != 0)
                    {
                        a -= icon.ActualWidth / 2;
                        if (a < 0)
                        {
                            a = 0;
                        }
                        if (a > width)
                        {
                            a = width;
                        }

                        double x = Math.Round((a / width) * (b - c));

                        if (x != slidingBarPosition)
                        {
              #if SILVERLIGHT
                            // Get absolute mouse position
                            Point mousePosition = e.GetPosition(null);

                            Storyboard storyboard = slidingBar.AnimateDoubleProperty("(Canvas.Left)", null, x, SlidingDurationInMilliseconds);
                            storyboard.Completed += (s, args) =>
                            {
                                // Select an icon on storyboard completion
                                // That is necessary because MouseOver state won't be proceeded correctly
                                SlidingBarStoryboardCompleted(mousePosition);
                                slidingBarPosition = x;
                            };
              #else
                            SetSlidingBarPosition(x);
              #endif
                        }
                    }
                }
            }
        }