This post describes about the programming aspects of Surface tags.If you are not familiar with surface and surface tags please see posts below
TagVisualizer is a ContentControl derived from SurfaceContentControl and it’s basic function is to show Tag Visualizations when the corresponding tag is placed on the surface. Tag Visualizations are added by means of TagVisualizationDefinition.For that the TagVisualizer has a property called Definitions which is of type TagVisualizationDefinitionCollection.Each TagVisualizationDefinition tells what to display when a tag is being placed.
This defines the visual against the tag value.The visual can be a UserControl and it is mentioned in the form of Uri.There are 2 types of tags in surface as you know.So there should be a mechanism to differentiate these tags while displaying.The method here used here is inheritance.ByteTagVisualizationDefinition which is derived from abstract class TagVisualizationDefinition deals with the byte tags and IdentityTagVisualizationDefinition derived from same ,deals with Identity tags.A simple xaml code which shows a red colored usercontrol on byte tag of value 10 is shown below.
ByteTagVisualization is a normal UserControl available in WPF.Hope this is clear like water.Shows the UserControl ByteTagVisualization when we place a byte tag with value 10 in the area covered by TagVisualizer.
This is again a ContentControl which can be used as Source in TagVisualizationDefinition.The advantage here is that, the TagVisualization class has some properties which are related to the tag and tag data.Below goes steps which explains how to create TagVisualization.
- Create a UserControl
- In the xaml file change the root tag as s:TagVisualization where s is xmlns:s="http://schemas.microsoft.com/surface/2008" namespace of surface controls.
- In the xaml.cs file change the base class to TagVisualization.Also change the constructor to suit the class.
A sample TagVisualization is given below
Getting tag values in TagVisualization and databinding
Even though the TagVisualization has the Property TagData we can’t use that in binding because that is not WPF friendly.
The above code won’t work
To enable databinding in TagVisualization we have to write our own properties which are data bindable.Then to get the value of tag which is placed over TagVisualizer override the OnGotTag method and get value from VisualizedTag property.
Now you can databind the value of the tag in xaml.
Download sample from here.