Touch Visualization Adapters
Every control that uses Touch Visualizations has an adapter that specifies how touch visualization works with respect to the control. This adapter specifies the following behavior:
-
Whether a tether is used and under what circumstances.
-
Whether a glow is used.
-
How the anchor point is determined for a tether.
-
Whether touch visualizations are shown for different touches.
Types of Touch Visualization Adapters
The default adapter is TouchVisualizerAdapter. TouchVisualizerAdapter is a general purpose adapter that is designed to provide visualizations for a variety of shapes. This default adapter is suitable for most applications.
The Microsoft Surface SDK also includes the following adapters:
- CompoundTouchVisualizerAdapter (used as a base class for other adapters)
- RectangleTouchVisualizerAdapter
- SurfaceButtonTouchVisualizerAdapter
- SurfaceScrollViewerTouchVisualizerAdapter
- TagVisualizerTouchVisualizerAdapter
TouchVisualizerAdapter can be resource-intensive. If you have a large number of items and performance is affected, you might want to use RectangleTouchVisualizerAdapter instead. The RectangleTouchVisualizerAdapter adapter treats all items as rectangles and is not appropriate for other shapes.
Changing the Touch Visualization Adapter
As an example, the following code example shows how to modify a ScatterViewItem control to use a RectangleTouchVisualizerAdapter by calling SetAdapter.
#region customAdapter RectangleTouchVisualizerAdapter adapter; /// <summary> /// Default constructor. /// </summary> public SurfaceWindow1() { InitializeComponent(); adapter = new RectangleTouchVisualizerAdapter(); TouchVisualizer.SetAdapter(scatterViewItem01, adapter); TouchVisualizer.SetAdapter(scatterViewItem02, adapter); // Add handlers for application-activation events. AddActivationHandlers(); } #endregion
The SetAdapter method is provided to simplify customizing adapters in C#. You can also use the OverrideMetadata method for the same result.
You can also implement this change in the XAML code, as the following example shows.
<s:SurfaceWindow x:Class="CV_CustomizeAdapter.SurfaceWindow2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="http://schemas.microsoft.com/surface/2008" Title="CV_CustomizeAdapter" > <Grid> <s:ScatterView Height="199" HorizontalAlignment="Left" Margin="64,110,0,0" Name="scatterView1" VerticalAlignment="Top" Width="405"> <s:ScatterViewItem Height="50" Name="scatterViewItem01" Width="100"> <s:TouchVisualizer.Adapter><s:RectangleTouchVisualizerAdapter /></s:TouchVisualizer.Adapter> </s:ScatterViewItem> <s:ScatterViewItem Height="50" Name="scatterViewItem02" Width="100"> <s:TouchVisualizer.Adapter><s:RectangleTouchVisualizerAdapter /></s:TouchVisualizer.Adapter> </s:ScatterViewItem> </s:ScatterView> </Grid> </s:SurfaceWindow>
Creating a Custom Touch Visualization Adapter
In some situations, you might also want to create your own custom touch visualization adapter. For example, you might want to specify one anchor point on each side of a control, corresponding to a reference mark on the control. To create this type of custom adapter, you can extend TouchVisualizerAdapter and override GetAnchorPosition.
Or, perhaps you want only some areas in your control to display touch visualizations. To create this type of custom adapter, you can extend TouchVisualizerAdapter and override ShowVisualization.
Note |
|---|
| If you create a custom control that is intended to use a particular adapter, the adapter must be a static instance. |
Testing the Code
If you are testing this code on a Windows 7 computer that does not have touch functionality, you can use the Input Simulator tool to simulate touch input.
© Microsoft Corporation. All rights reserved.
Note