use*_*589 5 windows wpf xaml scrollviewer touch
当我在列表框中使用滚动查看器时,当我通过触摸滚动到达列表框的末尾时,我的整个窗口都会弹跳.使用鼠标滚轮时不会出现此问题.如何禁用这种过度滚动/橡皮筋效果/反弹效果/弹跳效果.
我在Windows 8计算机上使用.NET Framework 4.5.
您可以在此视频中看到反弹效果:http://www.vidup.de/v/gQ2pI/
这是我的示例代码:
<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>
Run Code Online (Sandbox Code Playgroud)
您可以通过覆盖 OnManipulationBoundaryFeedback 方法来删除此行为:
public class FixedListBox : ListBox
{
protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true;
}
}
Run Code Online (Sandbox Code Playgroud)
另一种解决方案是将以下处理程序添加到ManipulationBoundaryFeedback
事件中(直接在 ListBox 上或通过样式):
<ListBox ManipulationBoundaryFeedback="OnManipulationBoundaryFeedback"/>
Run Code Online (Sandbox Code Playgroud)
或者:
<Style TargetType="{x:Type ListBox}">
<EventSetter Event="ManipulationBoundaryFeedback" Handler="OnManipulationBoundaryFeedback"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
后面有以下代码:
protected void OnManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
这些方法也适用于 ScrollViewer。