在 XAML 中停止 Listview 在 ScrollViewer 中捕获鼠标滚动
stop Listview from capturing mouse scroll inside ScrollViewer in XAML
你好,我正在制作 UWP 应用程序,在其中一个页面上我想要一个类似网站的体验,这意味着页面上有一个长滚动条。
我在页面的数据透视表中有一个 Listview。
看起来像这样。
<ScrollViewer
x:Name="scrollViewer"
ManipulationMode="All"
ScrollViewer.IsVerticalScrollChainingEnabled="True"
VerticalScrollBarVisibility="Auto">
<RelativePanel>
<Image />
<Pivot>
<Listview />
</Pivot>
<Other stuff />
</RelativePanel>
现在我的问题是,当我将鼠标悬停在列表视图以外的任何对象上时,鼠标滚动工作正常,一旦鼠标悬停在列表视图上,滚动就不起作用。
我试过像这样创建一个自定义的 ListView 样式,但是没有用。
<Style
x:Key="NoScrollListViewStyle"
TargetType="ListView">
<Setter
Property="IsTabStop"
Value="False" />
<Setter
Property="TabNavigation"
Value="Once" />
<Setter
Property="IsSwipeEnabled"
Value="False" />
<Setter
Property="ScrollViewer.HorizontalScrollBarVisibility"
Value="Disabled" />
<Setter
Property="ScrollViewer.VerticalScrollBarVisibility"
Value="Disabled" />
<Setter
Property="ScrollViewer.HorizontalScrollMode"
Value="Disabled" />
<Setter
Property="ScrollViewer.IsHorizontalRailEnabled"
Value="False" />
<Setter
Property="ScrollViewer.VerticalScrollMode"
Value="Disabled" />
<Setter
Property="ScrollViewer.IsVerticalRailEnabled"
Value="False" />
<Setter
Property="ScrollViewer.ZoomMode"
Value="Disabled" />
<Setter
Property="ScrollViewer.IsDeferredScrollingEnabled"
Value="False" />
<Setter
Property="ScrollViewer.BringIntoViewOnFocusChange"
Value="True" />
<Setter
Property="ItemContainerTransitions">
<Setter.Value>
<TransitionCollection>
<AddDeleteThemeTransition />
<ContentThemeTransition />
<ReorderThemeTransition />
<EntranceThemeTransition
IsStaggeringEnabled="False" />
</TransitionCollection>
</Setter.Value>
</Setter>
<Setter
Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<ItemsStackPanel
Orientation="Vertical" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="ListView">
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<ScrollViewer
x:Name="ScrollViewer"
AutomationProperties.AccessibilityView="Raw"
BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
HorizontalScrollMode="Disabled"
HorizontalScrollBarVisibility="Hidden"
IsHorizontalRailEnabled="False"
IsHorizontalScrollChainingEnabled="False"
IsVerticalScrollChainingEnabled="False"
IsVerticalRailEnabled="False"
IsDeferredScrollingEnabled="False"
TabNavigation="{TemplateBinding TabNavigation}"
VerticalScrollBarVisibility="Disabled"
VerticalScrollMode="Disabled"
ZoomMode="Disabled">
<ItemsPresenter
FooterTransitions="{TemplateBinding FooterTransitions}"
FooterTemplate="{TemplateBinding FooterTemplate}"
Footer="{TemplateBinding Footer}"
HeaderTemplate="{TemplateBinding HeaderTemplate}"
Header="{TemplateBinding Header}"
HeaderTransitions="{TemplateBinding HeaderTransitions}"
Padding="{TemplateBinding Padding}" />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
有什么想法吗?
我想到的解决方案是捕获 PointerWheelChanged
事件并移动 ScrollView
:
private void ListView_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
ScrollView.ScrollToVerticalOffset(ScrollView.VerticalOffset - e.GetCurrentPoint(ScrollView).Properties.MouseWheelDelta);
}
你好,我正在制作 UWP 应用程序,在其中一个页面上我想要一个类似网站的体验,这意味着页面上有一个长滚动条。
我在页面的数据透视表中有一个 Listview。
看起来像这样。
<ScrollViewer
x:Name="scrollViewer"
ManipulationMode="All"
ScrollViewer.IsVerticalScrollChainingEnabled="True"
VerticalScrollBarVisibility="Auto">
<RelativePanel>
<Image />
<Pivot>
<Listview />
</Pivot>
<Other stuff />
</RelativePanel>
现在我的问题是,当我将鼠标悬停在列表视图以外的任何对象上时,鼠标滚动工作正常,一旦鼠标悬停在列表视图上,滚动就不起作用。
我试过像这样创建一个自定义的 ListView 样式,但是没有用。
<Style
x:Key="NoScrollListViewStyle"
TargetType="ListView">
<Setter
Property="IsTabStop"
Value="False" />
<Setter
Property="TabNavigation"
Value="Once" />
<Setter
Property="IsSwipeEnabled"
Value="False" />
<Setter
Property="ScrollViewer.HorizontalScrollBarVisibility"
Value="Disabled" />
<Setter
Property="ScrollViewer.VerticalScrollBarVisibility"
Value="Disabled" />
<Setter
Property="ScrollViewer.HorizontalScrollMode"
Value="Disabled" />
<Setter
Property="ScrollViewer.IsHorizontalRailEnabled"
Value="False" />
<Setter
Property="ScrollViewer.VerticalScrollMode"
Value="Disabled" />
<Setter
Property="ScrollViewer.IsVerticalRailEnabled"
Value="False" />
<Setter
Property="ScrollViewer.ZoomMode"
Value="Disabled" />
<Setter
Property="ScrollViewer.IsDeferredScrollingEnabled"
Value="False" />
<Setter
Property="ScrollViewer.BringIntoViewOnFocusChange"
Value="True" />
<Setter
Property="ItemContainerTransitions">
<Setter.Value>
<TransitionCollection>
<AddDeleteThemeTransition />
<ContentThemeTransition />
<ReorderThemeTransition />
<EntranceThemeTransition
IsStaggeringEnabled="False" />
</TransitionCollection>
</Setter.Value>
</Setter>
<Setter
Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<ItemsStackPanel
Orientation="Vertical" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="ListView">
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<ScrollViewer
x:Name="ScrollViewer"
AutomationProperties.AccessibilityView="Raw"
BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
HorizontalScrollMode="Disabled"
HorizontalScrollBarVisibility="Hidden"
IsHorizontalRailEnabled="False"
IsHorizontalScrollChainingEnabled="False"
IsVerticalScrollChainingEnabled="False"
IsVerticalRailEnabled="False"
IsDeferredScrollingEnabled="False"
TabNavigation="{TemplateBinding TabNavigation}"
VerticalScrollBarVisibility="Disabled"
VerticalScrollMode="Disabled"
ZoomMode="Disabled">
<ItemsPresenter
FooterTransitions="{TemplateBinding FooterTransitions}"
FooterTemplate="{TemplateBinding FooterTemplate}"
Footer="{TemplateBinding Footer}"
HeaderTemplate="{TemplateBinding HeaderTemplate}"
Header="{TemplateBinding Header}"
HeaderTransitions="{TemplateBinding HeaderTransitions}"
Padding="{TemplateBinding Padding}" />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
有什么想法吗?
我想到的解决方案是捕获 PointerWheelChanged
事件并移动 ScrollView
:
private void ListView_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
ScrollView.ScrollToVerticalOffset(ScrollView.VerticalOffset - e.GetCurrentPoint(ScrollView).Properties.MouseWheelDelta);
}