Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Programmatically Enable TextBox Scrolling/Panning for Tablets

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.

like image 770
Blake Nelson Avatar asked Jul 13 '18 15:07

Blake Nelson


2 Answers

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

like image 103
1SaeedSalehi Avatar answered Nov 17 '22 23:11

1SaeedSalehi


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.

like image 1
Gaurang Dave Avatar answered Nov 18 '22 00:11

Gaurang Dave