6
votes

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?

2
Can you please add which platforms this is happening on? Is it happening on every platform Xamarin Forms is supported on?Jon Douglas
Yes sir - Windows 10onupdatecascade
As in Windows 10 Desktop? A windows 10 desktop won't have the touch gestures available if its a normal PC. You would have to do something like trackpad gestures (assuming you are on a laptop) to most closely simulate it. Otherwise Win10 desktop isn't going to act like Win10 Phone.Adam
These are tablets with Windows 10. They definitely have touch capability. Tapping works in the app, just not scrolling.onupdatecascade
Is the scrollview inside of a listview (at any point, is the listview a parent anywhere)QiMata

2 Answers

1
votes

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.

0
votes

The solution is to update Xamarin v2.0.0.6482, which came with my VS 2015 template, to v2.1.0.6529. Updating is a bit of a pain because of this problem https://bugzilla.xamarin.com/show_bug.cgi?id=39721. Once I got that installed scrolling started working with no other changes.

Scrolling is broken in the older version, on Windows, verified by a dev on the Xamarin forums.