0
votes

I have a WPF project which recognizes different inputs (e.g. finger, mouse, tagged objects) in the touch down method, I have an IF statement that recognizes if a tag is recognized and displays the data for the series and the value of the tag placed, then stores the data in the variable string type and displays it in the content of a label, the else recognizes if the touch is with a finger, and does the same thing.

However what I'm having trouble to achieve is being able to recognize the position in which a tag or finger is at the touch down poistion. I believe that a Point is needed to get the X&Y position of the touch but having tried multiple times with different things I cannot find a solution as to what parameters are needed.

The method

void SurfaceWindow1_TouchDown(object sender, TouchEventArgs e)
{
    TouchDevice c = e.TouchDevice;
    

    //by default it is a blob
    string type = "Blob"; 
    Point p = c.GetPosition();
    if (c.GetIsTagRecognized() == true)
    {
        type = "Tag";
        type += (" Series: " + c.GetTagData().Series.ToString("X", CultureInfo.InvariantCulture));
        type += (" Value: " + c.GetTagData().Value.ToString("X", CultureInfo.InvariantCulture));
     // type += (" Position: " //something here);
       
    }
    else if (c.GetIsFingerRecognized())
    {
        type = "Finger";
    }
    //display the type of item in a label
    InfoLabel.Content = type;
}

The errors received

Error 1: 'Point' is an ambiguous reference between 'System.Windows.Point' and 'System.Drawing.Point'

Error 2: No overload for method 'GetPosition' takes 0 arguments

1
Are you looking for something like TouchPoint p = e.GetTouchPoint(sender as IInputElement);? - dkozl
Must have edited, this message about 10 times! Yes that worked as I wanted. Thank you so much dkozl. :-) - Crofty

1 Answers

1
votes

Error 1: 'Point' is an ambiguous reference between 'System.Windows.Point' and 'System.Drawing.Point'

You're using 2 namespaces:

using System.Windows;
using System.Drawing;

and both contain definition of Point and compiler cannot decide which one you want to use when you do

Point p = c.GetPosition();

to fix it you can use var:

var p = c.GetPosition();

Error 2: No overload for method 'GetPosition' takes 0 arguments

As far as I can see TouchDevice does not have GetPosition() method but TouchEventArgs have TouchEventArgs.GetTouchPoint so instead you can do something like this:

var p = e.GetTouchPoint(sender as IInputElement).Position;