在 ScrollViewer 内旋转,scrollviewer 不会滚动

Pivot inside a ScrollViewer, scrollviewer wont scroll

我有一个包含许多 UI 元素的页面,它的垂直滚动像时间轴一样。在中间我有一个枢轴,当它获得焦点或鼠标指针进入滚动查看器时停止滚动。

<ScrollViewer x:Name="scrollViewer" VerticalScrollMode="Enabled" HorizontalScrollMode="Disabled">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="90"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition MaxWidth="180"/>
        <ColumnDefinition Width="360*" MaxWidth="1060"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
      <!-- more UI elements-->
    <Pivot ScrollViewer.HorizontalScrollMode="Disabled" ScrollViewer.VerticalScrollMode="Disabled" x:Name="InfoPivot" Title="Pivot" Grid.Column="1"  Grid.Row="4" VerticalAlignment="Top" MaxWidth="1060" HorizontalAlignment="Left" MinHeight="500">
        <PivotItem Header="Mylist">
            <GridView x:Name="theList" Margin="20,10,10,13" ItemTemplate="{StaticResource GridViewTemplate1}" VerticalAlignment="Top" HorizontalAlignment="Center"/>
        </PivotItem>
    </Pivot>
</Grid>

我找到了解决办法,但我希望有更好的方法。

编辑:更改了分区,使其感觉更像默认滚动条。

private void PivotItem_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
    if (e.GetCurrentPoint(scrollViewer).Properties.MouseWheelDelta == (-120))
    {
        // On Mouse Wheel scroll Backward
        scrollViewer.ChangeView(null, scrollViewer.VerticalOffset + Window.Current.CoreWindow.Bounds.Height / 7, null, false);
    }
    if (e.GetCurrentPoint(scrollViewer).Properties.MouseWheelDelta == (120))
    {
        // On Mouse Wheel scroll Forward
        scrollViewer.ChangeView(null,scrollViewer.VerticalOffset - Window.Current.CoreWindow.Bounds.Height / 7, null, false);
    }
}

documentation prescribes that we don't put a Pivot inside a ScrollViewer.

Don't place a Pivot control inside a scroll viewer to avoid conflicts with pivot's scrolling logic.

PointerWheelChanged 文档说:

Specific Windows Runtime controls may have class-based handling for the PointerWheelChanged input event. If so, the control probably has an override for the method OnPointerWheelChanged. Typically the event is marked handled by the class handler, and the PointerWheelChanged event is not raised for handling by any user code handlers on that control. A control might do this in order to support traversal of its child elements by using a pointer wheel action.

GridView and ListView 文档中的注释也适用于 Pivot

The PointerWheelChanged event does not bubble up from a GridView. This means that a control that has a GridView inside of it does not receive mouse wheel change messages if the pointer is over the GridView. For example, if you put a GridView inside of a ScrollViewer, you can't scroll the ScrollViewer with the mouse wheel when the pointer is over the GridView.