WPF Multi-touch Touch Points

I am trying to make a simple application, which, when the user touches the screen, the application creates a simple point object, ellipse or sth 2d, and when the user moves his finger, he must follow, but also when there is a scond tap, at the same time you need to create and a new facility and do the same with regard to user traffic. Whenever the user fingers, the object will be deleted.

To do this, I am trying to change the touchdrawing code from this link http://www.cookingwithxaml.com/recipes/wpf4/wpf4touch.zip , but I could not figure out which method I need to change?

Can you give some advice about this, please?

Thanks.

+4
source share
1 answer

Here is a sample xaml / C # code that does what I think you want:

MainWindow.xaml:

<Window x:Class="MultitouchExperiments.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Canvas x:Name="TouchCanvas" TouchDown="TouchCanvas_TouchDown" TouchUp="TouchCanvas_TouchUp" TouchMove="TouchCanvas_TouchMove" TouchLeave="TouchCanvas_TouchLeave" TouchEnter="TouchCanvas_TouchEnter" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black" IsManipulationEnabled="True" /> </Grid> </Window> 

MainWindow.xaml.cs:

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Diagnostics; namespace MultitouchExperiments { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { Dictionary<TouchDevice, Ellipse> _Followers = new Dictionary<TouchDevice, Ellipse>(); public MainWindow() { InitializeComponent(); } private void TouchCanvas_TouchDown(object sender, TouchEventArgs e) { TouchCanvas.CaptureTouch(e.TouchDevice); Ellipse follower = new Ellipse(); follower.Width = follower.Height = 50; follower.Fill = Brushes.White; follower.Stroke = Brushes.White; TouchPoint point = e.GetTouchPoint(TouchCanvas); follower.RenderTransform = new TranslateTransform(point.Position.X, point.Position.Y); _Followers[e.TouchDevice] = follower; TouchCanvas.Children.Add(follower); } private void TouchCanvas_TouchUp(object sender, TouchEventArgs e) { TouchCanvas.ReleaseTouchCapture(e.TouchDevice); TouchCanvas.Children.Remove(_Followers[e.TouchDevice]); _Followers.Remove(e.TouchDevice); } private void TouchCanvas_TouchMove(object sender, TouchEventArgs e) { if (e.TouchDevice.Captured == TouchCanvas) { Ellipse follower = _Followers[e.TouchDevice]; TranslateTransform transform = follower.RenderTransform as TranslateTransform; TouchPoint point = e.GetTouchPoint(TouchCanvas); transform.X = point.Position.X; transform.Y = point.Position.Y; } } private void TouchCanvas_TouchLeave(object sender, TouchEventArgs e) { //Debug.WriteLine("leave " + e.TouchDevice.Id); } private void TouchCanvas_TouchEnter(object sender, TouchEventArgs e) { //Debug.WriteLine("enter " + e.TouchDevice.Id); } } } 
+2
source

All Articles