因此,基本上我过滤触摸输入以仅识别来自每个屏幕的手指和标签触摸,除了我识别手指、标签和 Blob 触摸的训练屏幕。我通过覆盖 MainWindow 中的 OnPreviewTouchDown(TouchEventArgs e) 方法来做到这一点,MainWindow 是一个 SurfaceWindow。有关覆盖方法,请参见下面的代码。
protected override void OnPreviewTouchDown(TouchEventArgs e)
{
bool isFinger = e.TouchDevice.GetIsFingerRecognized();
bool isTag = e.TouchDevice.GetIsTagRecognized();
//Allows all touches on Train Screen. Only fingers and tags everywhere else
if (e.Source.ToString() != "dtt_app.TrainScreen")
{
if (isFinger == false && isTag == false)
{
e.Handled = true;
return;
}
}
base.OnPreviewTouchDown(e);
}
这就是我的令牌可视化代码的样子
for (int i = 1; i < 10; i++)
{
TagVisualizationDefinition TokenTagDef =
new TagVisualizationDefinition();
// The tag value that this definition will respond to.
TokenTagDef.Value = i;
// The .xaml file for the UI
TokenTagDef.Source =
new Uri("TokenVisualization.xaml", UriKind.Relative);
// The maximum number for this tag value.
TokenTagDef.MaxCount = 100;
// Orientation offset (default).
TokenTagDef.OrientationOffsetFromTag = 0.0;
// Physical offset (horizontal inches, vertical inches).
TokenTagDef.PhysicalCenterOffsetFromTag = new Vector(0.0, 0.0);
// Tag removal behavior (default).
TokenTagDef.TagRemovedBehavior = TagRemovedBehavior.Fade;
// Orient UI to tag? (default).
TokenTagDef.UsesTagOrientation = true;
// Add the definition to the collection.
MyTagVisualizer.Definitions.Add(TokenTagDef);
}
这是 TrainScreen 的 XAML 代码,它是一个设置为 MainWindow 内容的 UserControl
<UserControl x:Class="dtt_app.TrainScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="http://schemas.microsoft.com/surface/2008"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<s:TagVisualizer
Name="MyTagVisualizer"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="Transparent"
Height="Auto" Width="Auto"
VisualizationAdded="OnVisualizationAdded">
<Canvas Name="canvas" Width="{Binding ElementName=topWindow, Path=ActualWidth}" Height="{Binding ElementName=topWindow, Path=ActualHeight}">
<Label Width ="500" Canvas.Top="100" Content="Label" Name="Instruction" FontSize="30" HorizontalContentAlignment="Center"/>
<Popup Name="Positive" Width="240" Height="200" Placement="MousePoint" AllowsTransparency="True" IsEnabled="True" IsOpen="False">
<Image Source="images/SmileyFace.png">
</Image>
</Popup>
<Popup Name="Negative" Width="240" Height="200" Placement="MousePoint" IsEnabled="True" AllowsTransparency="True" IsOpen="False">
<Image Source="images/SadFace.png">
</Image>
</Popup>
</Canvas>
</s:TagVisualizer>
</Grid>
</UserControl>
我不知道为什么只要有标记的对象放在桌子上,就无法识别任何触摸输入。对此的任何帮助将不胜感激。请。我已经用尽了所有的可能性,而且我真的需要弄清楚这一点,因为时间已经不多了。提前致谢。