WPF – Stop Window to move when touch scrolling

The default behaviour of the WPF touch Scrollbar moves the entire Window when reaching the end of the scrolling area.
This behaviour can be overridden by the ManipulationBoundaryFeedback event:


    <ScrollViewer PanningMode="Both" x:Name="ScrollViewer"ManipulationBoundaryFeedback="ScrollViewer_ManipulationBoundaryFeedback">
        <StackPanel Width="300">
        </StackPanel>
    </ScrollViewer>

Code behind:


        private void ScrollViewer_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
        {
            e.Handled = true;
        }

Now to figure out a way to do this for all controls.

Edit:

Handling the event on the window didn’t remove the behaviour in the application.

I had to handle the event on the first element in the window (Grid) to prevent the window to move:

    <!-- Doesn't work -->
    <Window x:Class="TestControls.BoundaryFeedback"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="BoundaryFeedback" Height="300" Width="300"
    ManipulationBoundaryFeedback="Control_ManipulationBoundaryFeedback"
    >
    <!-- Works -->
    <Grid ManipulationBoundaryFeedback="Control_ManipulationBoundaryFeedback">
    </Grid>
    </Window>

Sources:
http://stackoverflow.com/questions/4505772/wpf-listbox-with-touch-inertia-pulls-down-entire-window
http://antonidol.wordpress.com/2012/01/24/how-to-stop-a-wpf-window-from-moving-by-removing-the-manipulationboundaryfeedback/

Advertisements

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: