Closed chaojian-zhang closed 1 year ago
I adapted your example using the workaround here:
https://www.telerik.com/forums/can%27t-scroll-when-mouse-over-header
That seems to work pretty well. I don't know why TextBox doesn't have this problem, but probably it's not worth investigating since this workaround seems to do the job.
myScrollViewer.AddHandler(ScrollViewer.MouseWheelEvent, new MouseWheelEventHandler(ScrollViewer_MouseWheel), true);`
private void ScrollViewer_MouseWheel(object sender, MouseWheelEventArgs e)
{
if (e.Delta > 0)
myScrollViewer.ScrollToVerticalOffset(myScrollViewer.VerticalOffset - 50);
else
myScrollViewer.ScrollToVerticalOffset(myScrollViewer.VerticalOffset + 50);
}
Try that out and let us know if it does the job for you.
I managed to handle PreviewMouseWheel
on TextEditor directly and incorporated your code to achieve what I want:
private void AvalonTextEditor_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
{
ScrollViewer scrollViewer = /*Somehow get reference to the ScrollViewer that contains this control*/;
if (e.Delta > 0)
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - 50);
else
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + 50);
e.Handled = true;
}
This would work as intended. Notice that binding to MouseWheel
will not work - the event will not be fired on Avalon TextEditor control.
You can close this issue, yes?
Scenario: When using TextEdit inside a large page which already has a scroll viewer, when the mouse is over TextEdit (NOT EVEN GIVING IT FOCUS), TextEdit EATS the scrolling/mousewheel events and prevent the containing control scrolling.
Expectation: Either 1) there is a way to disable Text Edit's scrolling altogether; 2) when document reaches its end, Text Edit should allow the hosting element to scroll. A related discussion can be seem here: https://www.telerik.com/forums/scroll-events-are-being-swallowed
Issue: Unlike regular TextBox, it's not possible to use Avalon Text Edit inside a scroll viewer because the control eats all the mousewheel/scrolling events.
Demonstration:
Cannot scroll the page at all when the cursor is over the Avalon Text Edit and there is no way to work around it!
https://user-images.githubusercontent.com/7077098/227248279-e93ac3e5-1897-4d8b-b014-1768af5a9505.mp4
Code:
Demonstration of Expected Behaviour:
Old good TextBox behaves just like expected.
https://user-images.githubusercontent.com/7077098/227249327-c654917d-b213-4587-adf0-56877788ac9e.mp4
Code: