Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would dragging a Xamarin scrollview not work when the mouse does work

I have a very simple Xamarin forms app which contains a scrollview, and inside is a stacklayout.

When deployed on Windows, the mouse works correctly to scroll the scrollview with a scrollbar. However, touch/drag does not work at all to scroll the same control. Do I have to do something special to enable touch/drag to scroll? I figured this would just work.

I'm not sure even where to start troubleshooting.

I am targeting Windows 10. Other platforms optional at this point.

The structure of UI classes I have is this:

ContentPage.Content = StackLayout1
StackLayout1.Children = { StackLayout2, Scrollview }
StackLayout2 contains an entry field and two buttons
ScrollView, which is the problem, contains another StackLayout
Inside that I have some labels and some grids

Following is a simplified repro. Running in the android emulator on my (touch capable) dev machine scrolling with touch works, running in the Windows 8.1 emulator, scrolling only works with a mouse, not with touch.

 public App() {

        StackLayout sl = new StackLayout();

        for (int i = 1; i < 20; i++) {
            sl.Children.Add( new Label { Text = "Label1", FontSize = 50, HeightRequest = 100 } );
        }

        ScrollView sv = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand };

        sv.Content = sl;

        ContentPage cp = new ContentPage();
        cp.Content = sv;

        MainPage = cp;


    }

Does Xamarin not handle Windows devices with touch, like Surface or other windows tablets? Or?

like image 467
onupdatecascade Avatar asked Apr 10 '16 21:04

onupdatecascade


1 Answers

There is an overriden method from Activity which is: public boolean onTouchEvent(MotionEvent event)

This is the general method that interprets all the touch events from the whole screen.

As you know every View has its own onTouchEvent() method that you could implement in order to add some custom implementation.It appears that these touch events go from the "inside" elements to the "outside" elements. I mean parent-child relations.

So in our case, the ScrollView returns true when the touch events are a horizontal. The activity's touch event will be handled only if the ScrollView touch event is not handled by itself then you are fine. Otherwise you have to override and implement the on touch event of scroll view and in some cases you have to return false so as for the whole layout to implement it.

like image 56
SimranTea Avatar answered Oct 18 '22 22:10

SimranTea