PointerWheelChanged事件

PointerWheelChanged事件

我有一个启用了VerticalScroll的GridView。在MainPage.xaml.cs中,我拦截了ScrollView的PointerWheelChanged事件。

在此PointerWheelChanged事件中,您可以知道方向盘是向上滚动还是向下滚动?

代码。

MainPage.xaml:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock x:Name="txbNumber" HorizontalAlignment="Center" Margin="0,-230,0,0" TextWrapping="Wrap" VerticalAlignment="Center"/>
    <GridView x:Name="TestGrid" HorizontalAlignment="Center" Height="200" Margin="0" VerticalAlignment="Center" Width="200" Background="#FF44AF0D">
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
        <GridViewItem Content="item"/>
    </GridView>
</Grid>


MainPage.xaml.cs:

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        TestGrid.AddHandler(UIElement.PointerWheelChangedEvent, new PointerEventHandler(OnPointerWheelChanged), true);
    }
    int number = 0;
    private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
    {
        txbNumber.Text = number.ToString();
        number += 1;
    }
}


先感谢您。

最佳答案

检查MouseWheelDeltaPointerRoutedEventArgs属性,如下所示:

private void WindowsPage_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
  var delta = e.GetCurrentPoint((UIElement)sender).Properties.MouseWheelDelta;
}


其值(int)指示车轮移动的方向。

从文档:


  正值表示轮子向前旋转(远离用户)或向右倾斜;负值表示滚轮向后旋转(朝用户方向)或向后倾斜

关于c# - PointerWheelChanged事件UWP,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46512093/

10-12 13:48