Reputation: 83
I have a GridView with enabled VerticalScroll. In MainPage.xaml.cs I intercepted the ScrollView's PointerWheelChanged Event.
In this PointerWheelChanged event, can you know whether the wheel scrolls up or down?
The code.
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;
}
}
Thank you in advance.
Upvotes: 2
Views: 1526
Reputation: 2090
Examine the MouseWheelDelta
property of the PointerRoutedEventArgs
as follows:
private void WindowsPage_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
var delta = e.GetCurrentPoint((UIElement)sender).Properties.MouseWheelDelta;
}
Its value (int) indicates the direction the wheel has moved.
From the docs:
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
Upvotes: 13