【问题标题】:PointerPoint.Properties.MouseWheelDelta tilt or scrollPointerPoint.Properties.MouseWheelDelta 倾斜或滚动
【发布时间】:2023-02-08 08:48:06
【问题描述】:

我有一个函数可以侦听我的 UIElement 的 PointerWheelChanged 事件。
我可以检索鼠标滚轮 Delta,但这并不能告诉我鼠标滚轮是否倾斜或向上/向下移动。

我怎样才能得到这些信息?

这是我获取增量的代码:

private void TestScrollViewer_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
    PointerPoint ptrPt = e.GetCurrentPoint((UIElement)sender);
    int delta = ptrPt.Properties.MouseWheelDelta;
    // positive: forward/right motion;  negative: backward/left motion
}

【问题讨论】:

    标签: c# scroll mousewheel winui-3


    【解决方案1】:

    你可以在Pointers里面使用IsHorizontalMouseWheel。请参阅下面的示例:

    主窗口.xaml

    <Window
        x:Class="MouseWheelTests.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:local="using:MouseWheelTests"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid RowDefinitions="Auto,*">
            <StackPanel Grid.Row="0">
                <TextBlock x:Name="WheelHorizontal" />
                <TextBlock x:Name="WheelVertical" />
            </StackPanel>
            <Grid
                Grid.Row="1"
                Background="Transparent"
                PointerWheelChanged="Grid_PointerWheelChanged" />
        </Grid>
    
    </Window>
    
    

    主窗口.xaml.cs

    using Microsoft.UI.Xaml;
    using Microsoft.UI.Xaml.Input;
    
    namespace MouseWheelTests;
    
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
        }
    
        private int WheelHorizontalValue { get; set; }
    
        private int WheelVerticalValue { get; set; }
    
        private void Grid_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
        {
            var properties = e.GetCurrentPoint((UIElement)sender).Properties;
    
            if (properties.IsHorizontalMouseWheel is true)
            {
                WheelHorizontalValue += properties.MouseWheelDelta;
                this.WheelHorizontal.Text = $"Horizontal: {WheelHorizontalValue}";
            }
            else
            {
                WheelVerticalValue += properties.MouseWheelDelta;
                this.WheelVertical.Text = $"Vertical: {WheelVerticalValue}";
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-01
      • 2023-03-09
      • 2013-06-21
      • 2011-08-18
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      相关资源
      最近更新 更多