wpf - xaml Scrollviewer - Disable Overscrolling / rubber-band-effect / snapback-effect / bouncing of whole window


Question: 

When I'm using the a scrollviewer in a listbox, my whole window is bouncing when I reach the end of the listbox via touch scrolling. This behavior does not appear when I use my mouse wheel. How can I disable this overscrolling/ rubber-band-effect / snap-back-effect /bouncing effect.

I'm working with .NET Framework 4.5 on a Windows 8 Computer.

You can see the bounce effect on this video: http://www.vidup.de/v/gQ2pI/

Here is my example code:

<Window x:Class="style_test_for_scrollviewer.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">

    <Grid>
        <ListBox Width="200">
            <WrapPanel Width="200"      ScrollViewer.PanningMode="VerticalOnly"         ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible">
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
                <Button Height="200" Width="200"></Button>
        </WrapPanel>
        </ListBox>
    </Grid>
</Window>



1 Answer: 

You can remove this behavior by overriding the OnManipulationBoundaryFeedback method :

public class FixedListBox : ListBox
{
    protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs e)
    {
        e.Handled = true;
    }
}

An other solution is to add the following handler to the ManipulationBoundaryFeedback event (directly on the ListBox or via a style):

<ListBox ManipulationBoundaryFeedback="OnManipulationBoundaryFeedback"/>

Or:

<Style TargetType="{x:Type ListBox}">
    <EventSetter Event="ManipulationBoundaryFeedback" Handler="OnManipulationBoundaryFeedback"/>
</Style>

With the following code behind:

protected void OnManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
    e.Handled = true;
}

Those methods works with the ScrollViewer too.

 

More Articles


.net - Linq To XML: Get Child XElement From Parent With Unknown Name

I currently have some XML similar to the following<First Node> <Second Node> <Third Node> <Fourth Node> 'Lots of Children in here </Fourth Node> </Third Node> </Second Node></First Node>The issue

c# - How to get the tag name using Linq to XML

If you have an XElement obj how do you get the tag name of the xelement object?doc.Descendants("name").Where(x => (string) x == cit.name).FirstOrDefault().Parenti would like to get the tagname of this xelement object.

Dynamic Xelement query in LINQ

I'm just wondering if it is possible to query a dynamic named xml element using LINQ.See below sample XML doc:<code><attendees><name>linda talor<name/><jur_a_credits>1.0<jur_a_credits/><jur_a_title>course 1<jur_a_title/><jur_f_credits>2.5<jur_


c# - Serialize string property as attribute, even if string is empty

public class Hat{ [XmlTextAttribute] public string Name { get; set; } [XmlAttribute("Color")] public string Color { get; set; }}var hat1 = new Hat {Name="Cool Hat", Color="Red"};var hat2 = new Hat {Name="Funky Hat", Color=null};This is what I get (notice missing color-attribute on Funky

c# - How to query the address? (LINQ to XML)

<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1"><Copyright>Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the cont

jquery.ui.touch.punch.js script is preventing input functionality on touch devices

It took me a little bit, but I figured out that I can't click on my inputs because of the touch.punch script I'm using to enable jquery UI drag functionality on touch devices. Anyone familiar with this script know why that might be? The form actually resides down the tree of the parent object. Does


c# - WPF ScrollViewer panning

I have a ScrollViewer object in my window that I want to be touch enabled. I have set its PanningMode to HorizontalOnly and it works good, but there are two things that I need to ask:1) When the ScrollViewer reaches the end of it's content, the whole window moves upon touching and swiping the object

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

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 sho

wpf - Windows 7 Touch Screen "Shrug"

We've got a WPF app that runs on Win 7. With touch gestures on in Win 7, while scrolling a ListView, the application "shrugs" on the screen when the end of the list is reached.This can be reproduced in Internet Explorer as well. If you load a web page that is long enough to produce a scroll bar, Win

c# - binding to dynamic resource in ItemsControl on the ItemsSource Property

Hey I was hoping someone could answer a couple questions for me. How am I supposed to ensure that the bound data to itemsource updates dynamically? I can't change bindingsource from staticresource to dynamic resource because the Source Property of the Object Binding is not a dependency property of a