I am trying to make it so that a user can ctrl-click outside of a richtextbox to scroll to a percentage of the richtextbox's maximum scroll amount based on the y.position of the mouse relative to the top of the richtextbox. Here's the code I'm currently using:
private void MainWindow_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Control)
{
if (!richTextBox1.IsMouseOver)
{
double d = (e.GetPosition(richTextBox1).Y / richTextBox1.ActualHeight);
if (d > 1) { d = 1; }
d = (richtextboxScrollViewer.ExtentHeight * d);
richtextboxScrollViewer.ScrollToVerticalOffset(d);
}
}
}
Right now it seems to work until I scroll to the bottom and then I have to click past halfway up the richtextbox in order to make it scroll upwards. What am I doing wrong?