停止Listview捕获XAML中ScrollViewer内的鼠标滚动

时间:2016-03-17 10:11:42

标签: c# xaml listview win-universal-app scrollviewer

您好我正在制作UWP应用程序,其中一个页面我想要一个像体验一样的网站,这意味着页面上有一个长卷轴。

我在页面的透视图中有一个Listview。

它看起来像这样。

<ScrollViewer
        x:Name="scrollViewer"
        ManipulationMode="All"
        ScrollViewer.IsVerticalScrollChainingEnabled="True"
        VerticalScrollBarVisibility="Auto">
        <RelativePanel>
            <Image />
    <Pivot>
        <Listview />
    </Pivot>
    <Other stuff /> 
    </RelativePanel>

现在我的问题是,当鼠标悬停在除listview之外的任何对象上时,鼠标滚动工作正常,只要鼠标位于listview上,滚动就不起作用。

我尝试过像这样创建一个自定义的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>

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

在解决方案中我想到的是抓住PointerWheelChanged事件并移动ScrollView

   private void ListView_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
    {
     ScrollView.ScrollToVerticalOffset(ScrollView.VerticalOffset - e.GetCurrentPoint(ScrollView).Properties.MouseWheelDelta);
    }