Search code examples
c#uwpwindows-10-universalmulti-touchgestures

touch two screen elements windows 10 universal


I have been asked to create a feature which requires you to simultaneously press two independent areas (buttons) of a touch interface. I have not been able to find out if this is possible (OK google)

I would assume you can simply intercept the touchstart events, if the device supports multi touch... and hook in that way, but I have not tried this, and I don't know if the second touchstart will be fired?

Does anyone have an experience with this?


Solution

  • It is possible to manipulate two elements with touch interactions simultaneously. However, there is no touchstart event in UWP. Instead, you may need use Manipulation events. And following is a simple sample:

    XAML:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Rectangle Name="BlueRectangle"
               Width="200" Height="200" Fill="Blue"
               ManipulationMode="All" HorizontalAlignment="Left" VerticalAlignment="Top" />
        <Rectangle Name="RedRectangle"
               Width="200" Height="200" Fill="Red"
               ManipulationMode="All" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
    </Grid>
    

    Code-Dehind:

    public sealed partial class MainPage : Page
    {
        private TranslateTransform dragBlueTranslation;
        private TranslateTransform dragRedTranslation;
    
        public MainPage()
        {
            this.InitializeComponent();
    
            dragBlueTranslation = new TranslateTransform();
    
            BlueRectangle.RenderTransform = this.dragBlueTranslation;
    
            BlueRectangle.ManipulationDelta += (s, e) =>
            {
                dragBlueTranslation.X += e.Delta.Translation.X;
                dragBlueTranslation.Y += e.Delta.Translation.Y;
            };
    
            dragRedTranslation = new TranslateTransform();
    
            RedRectangle.RenderTransform = this.dragRedTranslation;
    
            RedRectangle.ManipulationDelta += (s, e) =>
            {
                dragRedTranslation.X += e.Delta.Translation.X;
                dragRedTranslation.Y += e.Delta.Translation.Y;
            };
        }
    }
    

    And if you just need to detect the press, you can try with Tapped event. For more info, please see Touch interactions.