Search code examples
xamluwpcamerapinchzoom

UWP scale manipulation (pinch) events invoked inconsistently


I'm trying to detect the scale manipulation (pinch) in my application but for some reason the events are not invoked consistently (sometimes they are, sometimes they are not).

I've created a sample application where this can be easily reproduced:

<Page
    x:Class="Manipulate.MainPage"
    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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid Background="Red" ManipulationMode="Scale" ManipulationDelta="Grid_ManipulationDelta" ManipulationStarted="Grid_ManipulationStarted"/>
</Page>

using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace Manipulate
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void Grid_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine($"Started {e.}");
        }

        private void Grid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine($"Delta {e.Delta.Scale}");
        }
    }
}

In my actual application I'm trying to implement pinch to zoom on our custom camera implementation (inspired by https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/CameraManualControls) however I can't seem to get it work because neither ManipulationStarted nor ManipulationDelta are invoked consistently on every pinch gesture.

I'm seeing this on multiple Surface devices (Surface Book, Surface Go, Surface Pro 4).


Solution

  • Please check this Touch interactions document.

    Pinch Manipulation gesture Two or more fingers touch the screen and move closer together. In other words, you need to closer two pressed fingers. I have tested with simulator, and it works well. And here is sample code that you could refer.

    _compositeTransform.ScaleX = _compositeTransform.ScaleY = e.Delta.Scale;
      
    

    Update

    Derive from @Cosmin It seems there was an issue in the Windows build I was using 20226.1000. The issue was fixed Please check the blog here.