Is there a way to touch-enable scrolling in a WPF ScrollViewer?

Posted by Brian Sullivan on Stack Overflow See other posts from Stack Overflow or by Brian Sullivan
Published on 2010-05-13T19:28:49Z Indexed on 2010/05/13 19:34 UTC
Read the original article Hit count: 238

Filed under:
|

I'm trying to create a form in a WPF application that will allow the user to use iPhone-like gestures to scroll through the available fields. So, I've put all my form controls inside a StackPanel inside a ScrollViewer, and the scrollbar shows up as expected when there are too many elements to be shown on the screen.

However, when I try to test this on my touch-enabled device, a panning gesture (placing a finger down on the surface and dragging it upward) does not move the viewable area down as I would expect.

When I simply put a number of elements inside a ListView, the touch gestures work just fine. Is there any way to enable the same kind of behavior in a ScrollViewer?

My window is structured like this:

 <Window x:Class="TestTouchScrolling.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>        
    <ScrollViewer Name="viewer" VerticalScrollBarVisibility="Auto">
        <StackPanel Name="panel">
            <StackPanel Orientation="Horizontal">
                <Label>Label 1:</Label>
                <TextBox Name="TextBox1"></TextBox>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label>Label 2:</Label>
                <TextBox Name="TextBox2"></TextBox>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label>Label 3:</Label>
                <TextBox Name="TextBox3"></TextBox>
            </StackPanel>

            <!-- Lots more like these -->

        </StackPanel>
    </ScrollViewer>
</Grid>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about touch