Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 334
user2440589 Avatar asked May 31 '13 13:05

user2440589


1 Answers

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.

like image 147
Max Avatar answered Nov 20 '22 09:11

Max