2013-05-31 12 views
5

Kiedy używam przewijania w polu listy, całe moje okno odskakuje, gdy docieram do końca listbox poprzez touch scrolling. To zachowanie nie pojawia się, gdy używam kółka myszy. Jak mogę wyłączyć efekt overscrolling/rubber-band-effect/snap-back-effect/bouncing?Przewijanie xaml - Wyłącz przewijanie/efekt gumki/efekt snapback/odbijanie całego okna

Pracuję z .NET Framework 4.5 na komputerze z systemem Windows 8.

można zobaczyć efekt odbijanie na tym filmie: http://www.vidup.de/v/gQ2pI/

Oto mój przykładowy kod:

<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> 

Odpowiedz

4

można usunąć ten problem poprzez nadpisanie metody OnManipulationBoundaryFeedback:

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

Innym rozwiązaniem jest dodanie następującego handler'a do zdarzenia ManipulationBoundaryFeedback (bezpośrednio na ListBox lub poprzez styl):

<ListBox ManipulationBoundaryFeedback="OnManipulationBoundaryFeedback"/> 

Lub:

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

z następującego kodu za:

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

Metody te współpracuje z ScrollViewer też.

Powiązane problemy