//Event handlers

        private void scrubberGrid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton != MouseButton.Left)
            {
                return;
            }

            //change the scrub pos to the place we clicked on
            double clickedPos = e.GetPosition(this).X;

            SelectedTime = IPannableZoomableUtils.GlobalToLocalPos(clickedPos, this);
        }
        private void UpdateScrubber()
        {
            //Update the handle's position
            double pos = IPannableZoomableUtils.LocalToGlobalPos((double)SelectedTime, this);

            Thickness margin = scrubHandle.Margin;

            margin.Left        = pos - scrubHandle.Width / 2;
            scrubHandle.Margin = margin;

            //Update the seek line's position
            margin                 = scrubberRedLine.Margin;
            margin.Left            = pos;
            margin.Top             = scrubHandle.Margin.Top + scrubHandle.Height;
            scrubberRedLine.Margin = margin;
        }
        private void SnapToPoint()
        {
            //Get all the snap points
            double[] snapPoints = GetSnapPoints();

            //Don't go on if there are no snap points
            if (snapPoints.Length == 0)
            {
                return;
            }

            //Find the closest snap point
            double closestSnapPoint    = 0;
            double closestSnapDistance = double.MaxValue;

            foreach (double point in snapPoints)
            {
                //Update the closest snap point
                double dist = Math.Abs(point - scrubberTargetTime);

                if (dist < closestSnapDistance)
                {
                    closestSnapDistance = dist;
                    closestSnapPoint    = point;
                }
            }

            //Find the scrubber's physical distance from the snap point
            double physicalScrubberPos = IPannableZoomableUtils.LocalToGlobalPos(scrubberTargetTime, this);
            double physicalSnapPos     = IPannableZoomableUtils.LocalToGlobalPos(closestSnapPoint, this);

            double physicalDistance = Math.Abs(physicalScrubberPos - physicalSnapPos);

            //Snap to the point if it's close enough
            const double SNAP_MARGIN = 5;

            if (physicalDistance < SNAP_MARGIN)
            {
                SelectedTime = closestSnapPoint;
            }
        }