Reputation: 559
I have a pixelsense tabletop and want to recognize if a tag was added. Since the hardware is quite old, it is hard to find information. Here I could find an example how to recognize tags, but only with predefined values:
<s:TagVisualizer Name="TagVisualizer">
<s:TagVisualizer.Definitions>
<s:ByteTagVisualizationDefinition Value="192"
Source="SampleTagVisualization.xaml"
UsesTagOrientation="True"
TagRemovedBehavior="Fade"
PhysicalCenterOffsetFromTag="7.5,4.5"/>
</s:TagVisualizer.Definitions>
</s:TagVisualizer>
I just want to raise an event, if a tag (whatever value) was added and then match with a database entry. This should work with at least two objects at the same time.
In the TagVisualizer
class I found the following events:
public event TagVisualizerEventHandler PreviewVisualizationInitialized;
public event TagVisualizerEventHandler VisualizationAdded;
public event TagVisualizerEventHandler PreviewVisualizationMoved;
public event TagVisualizerEventHandler PreviewVisualizationRemoved;
public event TagVisualizerEventHandler VisualizationInitialized;
public event TagVisualizerEventHandler PreviewVisualizationAdded;
public event TagVisualizerEventHandler VisualizationMoved;
public event TagVisualizerEventHandler VisualizationRemoved;
But as as far as I've tried, the VisualizationAdded
event is only raised, if there exist some TagVisualizer Definitions.
Upvotes: 1
Views: 50
Reputation: 559
I tried the suggestion by Robert Levy and caught the TouchDown Event on the main panel <Grid TouchDown="TouchDetected">
and printed out the resulting tag value
private void TouchDetected(object sender, TouchEventArgs e)
{
if (e.TouchDevice.GetIsTagRecognized())
{
var tagData = e.TouchDevice.GetTagData();
Console.WriteLine("Touch_VALUE: " + tagData.Value);
}
else
{
Console.WriteLine("No Tag recognized.");
var tagData = e.TouchDevice.GetTagData();
Console.WriteLine("No_Touch_VALUE: " + tagData.Value);
}
}
As it always returned 0, I tried a different approach and added a TagVisualizer
to the main Window with a single TagVisualizationDefinition
(other way the event VisualizationAdded
is not invoked)
<s:TagVisualizer x:Name="MyTagVisualizer"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="Transparent"
Width="auto"
Height="auto">
<s:TagVisualizer.Definitions>
<s:TagVisualizationDefinition
Source="UserControls/ProductMenuVisualization.xaml"/>
</s:TagVisualizer.Definitions>
</s:TagVisualizer>
Even with one Defintion I the event is fired for every tag and I can add the values to a Dictionary and check if it is already added or not.
If you wonder, I subscribe to the events in code
MyTagVisualizer.VisualizationAdded += AddProductMenu;
MyTagVisualizer.VisualizationRemoved += RemoveProductMenu;
MyTagVisualizer.VisualizationMoved += MoveProductMenu;
It is not perfekt but it works.
Upvotes: 0
Reputation: 29073
You can use the ContactDown event on any element to look at any surface input. IIRC, there is a Contact.ContactType property on that event which should tell you it’s a tag and then Contact.TagValue tells you the value. This even and it’s peers behave the same as MouseDown and it’s peers.
For TagVisualizer, the purpose of this is to simplify a lot of common code needed to work with tags beyond detecting them. Generally speaking, you’ll want to have a database that defines the tag values you care about along with the positioning of those tags relative to the physical object. A good practice would be to query your database for all of this info and then configure TagVisualizer to be on the lookout for all of those tags you care about. There won’t be a noticeable performance impact to having a lot of definitions configured.
Btw, for API docs, you should see a .chm file inside the SDK installation which will let you read the docs offline since they are no longer accessible online.
This is all from memory so I hope it’s somewhat accurate and helpful!
(disclaimer: former PM for Surface dev platform)
Upvotes: 1