Pivot inside a ScrollViewer, scrollviewer wont scroll

北战南征 提交于 2019-12-02 06:48:38

问题


I have a page that has many UI elements and its scrollable vertical like a Timeline. In the middle I have a pivot that when its gets focus or the mouse pointer enters the scrollviewer stop scrolling.

<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>


回答1:


I found a solution but I hope there is a better way.

Edit: Changed the division it makes it feel more like the the default scroll.

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);
    }
}



回答2:


The 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.

The PointerWheelChanged doc says:

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.

A note on the GridView and ListView docs also applies to 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.



来源:https://stackoverflow.com/questions/32429965/pivot-inside-a-scrollviewer-scrollviewer-wont-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!