ViewboxLimits
#3
Thanks! Your new code got me most of the way there and it fixed ALL of my concerns with a little modification. With your suggested code, panning completely stopped - I was always stuck in the center, even when I should be able to pan up or down (but not left or right). However it was easy enough to modify to get the desired behavior.

Here's what I did to fix it:

1. On the painter sample, on the ScrollViewer, I set the scrollbars for horizontal / vertical to "Auto" for viability.
2. I gave the ScrollViewer a name ("scroll") so I could reference in the code behind.
3. I added two new variables to your suggested code called newX and newY. There values either equal the e.NewViewboxValue.X/Y or the forced center X/Y depending on whether the scrollbars are visible for that direction.

Here's the final code that worked perfectly:
Code:
       private void ZoomPanel1_PreviewViewboxChanged(object sender, Controls.ViewboxChangedRoutedEventArgs e)
       {
           double newWidth = e.NewViewboxValue.Width;
           double newHeight = e.NewViewboxValue.Height;
           double newX = (scroll.ComputedHorizontalScrollBarVisibility == Visibility.Visible) ? e.NewViewboxValue.X : 0.5 - newWidth / 2.0;
           double newY = (scroll.ComputedVerticalScrollBarVisibility == Visibility.Visible) ? e.NewViewboxValue.Y : 0.5 - newWidth / 2.0;

           e.NewViewboxValue = new Rect(newX, newY, newWidth, newHeight);
       }
  


Messages In This Thread
ViewboxLimits - by B.O.B. - 06-14-2019, 06:07 PM
RE: ViewboxLimits - by abenedik - 06-19-2019, 12:42 PM
RE: ViewboxLimits - by B.O.B. - 06-19-2019, 03:26 PM
RE: ViewboxLimits - by abenedik - 06-20-2019, 12:22 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)