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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With