2013-05-31 36 views
5

當我在列表框中使用滾動查看器時,當我通過到達列表框的末端時,整個窗口彈起觸摸滾動。當我使用我的鼠標滾輪時,此行爲未出現。我怎樣才能禁用這種過度滾動/橡皮筋效應/回彈效應/彈跳效果。xaml滾動查看器 - 禁用整個窗口的滾動/橡皮筋效果/回彈效果/彈跳

我正在使用Windows 8計算機上的.NET Framework 4.5。

你可以看到這部影片的反彈效應:http://www.vidup.de/v/gQ2pI/

這裏是我的示例代碼:

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

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

回答

4

您可以通過重寫OnManipulationBoundaryFeedback在方法刪除此行爲另一種解決方案是將以下處理程序添加到ManipulationBoundaryFeedback事件(直接在ListBox上或通過樣式):

<ListBox ManipulationBoundaryFeedback="OnManipulationBoundaryFeedback"/> 

或者:

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

隨着後面的下面的代碼:

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

這些方法的工作原理與ScrollViewer中了。