我已经设置了以下简单的XAML页面:
<Page ...>
<ScrollViewer>
<StackPanel>
<Border Height="100">
<TextBlock Text="Block 1" />
</Border>
<ListView Height="200">
<ListViewItem Content="Lorem" />
<ListViewItem Content="Ipsum" />
<ListViewItem Content="Lorem" />
<ListViewItem Content="Ipsum" />
<ListViewItem Content="Lorem" />
<ListViewItem Content="Ipsum" />
</ListView>
<Border Height="800">
<TextBlock Text="Block 2" />
</Border>
</StackPanel>
</ScrollViewer>
</Page>
通常我对卷轴感到满意&#34;反弹&#34;当用户滚动到页面的顶部/底部时顶级ScrollViewer
提供的效果。但是,当在ListView
内滚动时,我会得到双反弹;即,ListView和ScrollViewer都提供了弹性拉伸。我觉得这是一个奇怪的用户体验。
有没有办法让ListView反弹同时防止它传递给父滚动容器?
答案 0 :(得分:0)
这种情况只发生在触摸输入而不是鼠标输入上,可能有很多种方法,但它是最快捷方便的。
这将有效
<强> XAML 强>
<ScrollViewer Name="sv"> <!-- Name added -->
<StackPanel>
<Border Height="100">
<TextBlock Text="Block 1" />
</Border>
<ListView Name="lv" Height="200"> <!-- Name added -->
<ListViewItem Content="Lorem" />
<ListViewItem Content="Ipsum" />
<ListViewItem Content="Lorem" />
<ListViewItem Content="Ipsum" />
<ListViewItem Content="Lorem" />
<ListViewItem Content="Ipsum" />
</ListView>
<Border Height="800">
<TextBlock Text="Block 2" />
</Border>
</StackPanel>
</ScrollViewer>
<强> C#强>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
//Add this two event handlers and you can add this event handler from xaml also.
lv.AddHandler(UIElement.PointerEnteredEvent, new PointerEventHandler(OnPointerEntered), true);
lv.AddHandler(UIElement.PointerExitedEvent, new PointerEventHandler(OnPointerExited), true);
}
private void OnPointerEntered(object sender, PointerRoutedEventArgs e)
{
sv.VerticalScrollMode = ScrollMode.Disabled;
}
private void OnPointerExited(object sender, PointerRoutedEventArgs e)
{
sv.VerticalScrollMode = ScrollMode.Enabled;
}
}