Exemple #1
0
 private void DisplayScroll_MouseMove(object sender, MouseEventArgs e)
 {
     if (lastDragPoint.HasValue)
     {
         Point  posNow = e.GetPosition(DisplayScroll);
         double dX     = posNow.X - lastDragPoint.Value.X;
         double dY     = posNow.Y - lastDragPoint.Value.Y;
         lastDragPoint = posNow;
         DisplayScroll.ScrollToHorizontalOffset(DisplayScroll.HorizontalOffset - dX);
         DisplayScroll.ScrollToVerticalOffset(DisplayScroll.VerticalOffset - dY);
     }
 }
Exemple #2
0
 public void ProcessIndicatorInput(double x)
 {
     x -= ScrollIndicator.Margin.Left;
     x  = x / ((ScrollIndicator.Parent as FrameworkElement).ActualWidth - ScrollIndicator.Margin.Left - ScrollIndicator.Margin.Right);
     DisplayScroll.ScrollToHorizontalOffset(x * DisplayScroll.ScrollableWidth);
 }
Exemple #3
0
        private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
#if DEBUG
            if (DisplayScroll.CanContentScroll)
            {
                Console.WriteLine("ScrollChangedEvent just Occurred");
                Console.WriteLine("ExtentHeight is now " + e.ExtentHeight);
                Console.WriteLine("ExtentWidth is now " + e.ExtentWidth);
                Console.WriteLine("ExtentHeightChange was " + e.ExtentHeightChange);
                Console.WriteLine("ExtentWidthChange was " + e.ExtentWidthChange);
                Console.WriteLine("HorizontalOffset is now " + e.HorizontalOffset);
                Console.WriteLine("VerticalOffset is now " + e.VerticalOffset);
                Console.WriteLine("HorizontalChange was " + e.HorizontalChange);
                Console.WriteLine("VerticalChange was " + e.VerticalChange);
                Console.WriteLine("ViewportHeight is now " + e.ViewportHeight);
                Console.WriteLine("ViewportWidth is now " + e.ViewportWidth);
                Console.WriteLine("ViewportHeightChange was " + e.ViewportHeightChange);
                Console.WriteLine("ViewportWidthChange was " + e.ViewportWidthChange);
                Console.WriteLine("ActualHeight is now " + DisplayScroll.ActualHeight);
                Console.WriteLine("ActualWidth is now " + DisplayScroll.ActualWidth);
                Console.WriteLine("--------------------------------------------------------------");
                //ActualHeight = ViewportHeight + HorizontalScrollbarHeight
            }
#endif

            DisplayScroll.UpdateLayout();

            if (e.ViewportHeightChange != 0 || e.ViewportWidthChange != 0)
            {
                _zoomValue = ZoomToFit();
                var scale = new ScaleTransform(_zoomValue, _zoomValue);
                DisplayImage.LayoutTransform = scale;

                DisplayScroll.UpdateLayout();
            }

            if (e.ExtentHeightChange != 0 || e.ExtentWidthChange != 0)
            {
                Point?targetBefore = null;
                Point?targetNow    = null;

                if (lastMousePositionOnTarget.HasValue)
                {
                    targetBefore = lastMousePositionOnTarget;
                    targetNow    = Mouse.GetPosition(DisplayImage);

                    lastMousePositionOnTarget = null;
                }

                if (targetBefore.HasValue)
                {
                    double dXInTargetPixels = targetNow.Value.X - targetBefore.Value.X;
                    double dYInTargetPixels = targetNow.Value.Y - targetBefore.Value.Y;

                    double multiplicatorX = e.ExtentWidth / DisplayImage.ActualWidth;
                    double multiplicatorY = e.ExtentHeight / DisplayImage.ActualHeight;

                    double newOffsetX = DisplayScroll.HorizontalOffset - dXInTargetPixels * multiplicatorX;
                    double newOffsetY = DisplayScroll.VerticalOffset - dYInTargetPixels * multiplicatorY;

                    if (double.IsNaN(newOffsetX) || double.IsNaN(newOffsetY))
                    {
                        return;
                    }

                    DisplayScroll.ScrollToHorizontalOffset(newOffsetX);
                    DisplayScroll.ScrollToVerticalOffset(newOffsetY);
                }
            }
        }