locked
Pointer Position doesn't work for touch input

    Question

  • I'm implementing a custom drag and drop feature using the Window.Current.CoreWindow.PointerPosition to know where to drop the item, but the PointerPosition only updates for mouse input and doesn't work for touch input. I'm confused I thought "Pointer" was meant to be all three types of input-pen, touch, mouse.

    Here's some sample code to see for yourself.

    <Page x:Class="PointerPositionExperiment.MainPage"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="using:PointerPositionExperiment"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          mc:Ignorable="d">
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Rectangle Fill="Blue"
                       Width="100"
                       Height="100"
                       ManipulationDelta="UIElement_OnManipulationDelta"
                       ManipulationMode="All"></Rectangle>
        </Grid>
    </Page>

            private void UIElement_OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
            {
                Point pointerPosition = Window.Current.CoreWindow.PointerPosition;
                Debug.WriteLine(pointerPosition);
            }

    Notice the output for touch input doesn't update.

    Monday, June 16, 2014 6:45 PM

Answers

  • Which pointer do you want? As you note, there are many.

    During manipulation the ManipulationDeltaRoutedEventArgs.Position will be more relevant. Even then that'll be a compound value since most manipulations involve multiple pointers.

    If you want to track the actual pointers you'll need to get the IDs from PointerPressed and then call PointerPoint.GetCurrentPoint(pointerId) to get the value of the specific touch point you want.

    --Rob


    Monday, June 16, 2014 7:50 PM
    Owner

All replies

  • Which pointer do you want? As you note, there are many.

    During manipulation the ManipulationDeltaRoutedEventArgs.Position will be more relevant. Even then that'll be a compound value since most manipulations involve multiple pointers.

    If you want to track the actual pointers you'll need to get the IDs from PointerPressed and then call PointerPoint.GetCurrentPoint(pointerId) to get the value of the specific touch point you want.

    --Rob


    Monday, June 16, 2014 7:50 PM
    Owner
  • Yes this worked, thanks.


    Tuesday, June 17, 2014 3:09 PM