0

I want to implement an UI for finger controling, in WPF C# .Net framework, VS2019.

ManipulationDelta event is added on a Rectangle and it supposed to work continiously. But when I test it, it triggered only once at the moment I tapped(touch down). This event should be triggered continuously while my finger pressing.

Target: Show the position of pointer within the rectangle area.

XAML:

<Window x:Class="WpfApp5.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp5"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Grid Margin="0,0,-322,-112">
    <Rectangle 
        ManipulationDelta="Rectangle_ManipulationDelta"
        TouchMove="Rectangle_TouchMove"
        
        Fill="#FFF4F4F5" 
        HorizontalAlignment="Left" 
        Height="274" Margin="162,70,0,0" 
        Stroke="Black" 
        VerticalAlignment="Top" 
        Width="582" IsManipulationEnabled="True"/>
    
    <TextBlock 
        x:Name="textBlock" 
        HorizontalAlignment="Left" 
        TextWrapping="Wrap" 
        VerticalAlignment="Top" 
        Margin="31,26,0,0"><Run Text="TextBlock"/></TextBlock>
</Grid>

Here is the event to print the postion of finger:

C#:

namespace WpfApp5{
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Rectangle_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        
    }

    private void Rectangle_TouchMove(object sender, TouchEventArgs e)
    {
            textBlock.Text = "Manipulation Touch: " + Mouse.GetPosition(Application.Current.MainWindow).ToString();
    }
}

}

  • UI tested on Windows10 Simulator v16 and Surface Pro

  • Holding right-clicking is disabled

  • A test video is here to describe the issue with subtitle Test Video

  • After testing, the event likes TouchMove, MouseMove, ManipulationDelta will be fired only if the cursor "get into" the border of element. I want to trigger this event within target area. Or should I use another event to achieve this?

Any suggestion is appreciated! Thank you.

nfszero
  • 1
  • 1
  • 1
    "*This event should be triggered continuously*" - this is not how it is supposed to work. As the "Delta" in the name implies, the event is only fired when a change in either Scale, Rotation or Translation occurs. – Clemens Sep 14 '21 at 05:24
  • Yeah, I keep finger moving after touched, for example: touch>draw a circle>raise, this Delta event should be triggered during "draw a circle", doesn't it? But it only fire once. – nfszero Sep 14 '21 at 05:32
  • https://www.youtube.com/watch?v=4rKwJGqD0o0 The video to describe the problem. – nfszero Sep 14 '21 at 06:00
  • "*trigger this event within target area*" - if that means the parent element of the Rectangle, e.g. a Canvas, the event handler should apparently be attached to that element. – Clemens Sep 14 '21 at 07:02
  • There are under , and the "target area" is . The XAML is also updated for better understanding. In this case, which one is the parent element? – nfszero Sep 14 '21 at 07:26
  • Actually I don't need to move the Rectangle. I just want to monitor the position of cursor when I touch within the rectangle. – nfszero Sep 14 '21 at 07:47
  • 1
    @nfszero Have you checked whether the events are fired by debug message? The TextBox will not be timely updated during the manipulation is under way. – emoacht Sep 14 '21 at 09:25
  • @emoacht I found a way to do this, I will reply in answer. – nfszero Sep 14 '21 at 10:54

1 Answers1

0

I found that I use worng event, I should use TouchMove instead of ManipulationDelta(manipulation means manipulation for translation, zoom, etc, it's not necessary in this case).

And the flag should be set to false:

IsManipulationEnabled="false"

It working now! And thanks for who paticipating this discussion.

nfszero
  • 1
  • 1