我有一个启用了 VerticalScroll 的 GridView。在 MainPage.xaml.cs 中,我拦截了 ScrollView 的 PointerWheelChanged 事件。
在这个PointerWheelChanged事件中,你能知道滚轮是向上滚动还是向下滚动吗?
代码。
主页.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;
}
}
提前谢谢你。
检查 MouseWheelDelta
PointerRoutedEventArgs
的属性如下:
private void WindowsPage_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
var delta = e.GetCurrentPoint((UIElement)sender).Properties.MouseWheelDelta;
}
它的值(int)表示轮子移动的方向。
来自文档:
A positive value indicates that the wheel was rotated forward (away from the user) or tilted to the right; a negative value indicates that the wheel was rotated backward (toward the user) or tilted to the
我是一名优秀的程序员,十分优秀!