15
votes

I am working with a WPF application that will be used on Windows tablets. The issue I am having is that I cannot scroll through a large multi-line TextBox on a tablet by pressing and dragging the content. However, it still scrolls on a desktop with a mouse wheel.

This question (Enable swipe scrolling on Textbox control in WPF Scrollviewer) seems to answer the same problem I am having, but I need to do it programmatically. This is what I am doing to set the panning mode of the TextBox:

txtLongText.SetValue(ScrollViewer.PanningModeProperty, PanningMode.None);

Which I can tell is working because the click & drag text selection is now disabled, but the content still does not scroll. I am also setting the panning mode of the outer ScrollViewer as such:

popupScrollView.PanningMode = PanningMode.Both;

The popupScrollView object is then being set as the content inside a Popup.

The only thing I can think of is if there is somewhere else higher up that I need to be setting the panning mode? Any help would be appreciated. Thanks.

3
Please add some code samples to replicate this issue. - Jagadeesh Govindaraj

3 Answers

1
votes

i have same problem with touch devices. i have a tricky way to handle this kind of issues

You have to handle touch event manually i have written some codes to handle touch events manually

when UIElement_OnTouchDown(object sender, TouchEventArgs e) event occurred you can keep position of touched position by eventArgs.GetTouchPoint(this).Position.Y.

after that, you can determine is scroll happened or not by watching the position changes.

here is my sample gist , i use this approach for same issue with touch devices

1
votes

I think you require to use three properties to achieve this.

ScrollViewer.PanningMode
ScrollViewer.PanningDeceleration
ScrollViewer.PanningRatio

By default, PanningMode sets to None, but set it to another value will enable touch scrolling.

Another thing you can try is to set ScrollViewer CanContentScroll to true.

0
votes

While Im not sure there is a viable way to solve that using wpf only, I recommend trying to implement html UI inside your wpf application using DoNetBrowser, link.

Then you can use the textarea control in html, which in default lets you scroll on mobile. Hope this answer helped you.