按c#检测多点触控

时间:2014-09-18 23:26:59

标签: c# wpf touch

我想检测触摸事件并在我的手指触及时做一些事情。

我需要的活动是什么?

我尝试了Manipulation *,Pointer *,Touch *,Stylus *,Holding *等......

如果你有一个示例代码,那就更好。

我所拥有的最准确的代码就是这个。但只能用手指移动。

<Window x:Class="WpfApplication2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Rectangle Name="Rect1" IsManipulationEnabled="True" Fill="Blue" HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100" Margin="108,50,309,169" ManipulationDelta="Rect1_ManipulationDelta"  />
    <Rectangle Name="Rect2" IsManipulationEnabled="True" Fill="Blue" HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100" Margin="338,50,79,169"  ManipulationDelta="Rect2_ManipulationDelta" />
    <TextBox Name="Text1" Text="0" HorizontalAlignment="Left" Height="23" Margin="108,267,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="100"/>
    <TextBox Name="Text2" Text="0" HorizontalAlignment="Left" Height="23" Margin="338,267,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="100"/>
</Grid>

namespace WpfApplication2
{

public partial class MainWindow : System.Windows.Window
{
    System.Windows.Input.ManipulationModes currentMode = System.Windows.Input.ManipulationModes.All;

    public MainWindow()
    {
        InitializeComponent();
    }

    private void Rect1_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
    {
        int variable = 0;

        variable = Convert.ToInt32(Text1.Text);
        variable++;
        Text1.Text = variable.ToString();
    }

    private void Rect1_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        int variable = 0;

        variable = Convert.ToInt32(Text1.Text);
        variable++;
        Text1.Text = variable.ToString();
    }

    private void Rect2_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
    {
        int variable = 0;

        variable = Convert.ToInt32(Text2.Text);
        variable++;
        Text2.Text = variable.ToString();
    }

    private void Rect2_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        int variable = 0;

        variable = Convert.ToInt32(Text2.Text);
        variable++;
        Text2.Text = variable.ToString();
    }

}

}

2 个答案:

答案 0 :(得分:0)

UIElement / ContentElement.TouchDown是您完成所需工作所需的事件。

示例:

<Rectangle Name="Rect1" IsManipulationEnabled="True" Fill="Blue" HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100" Margin="108,50,309,169" TouchDown="Rect1_TouchDown" />

private void Rect1_TouchDown(object sender, TouchEventArgs e)
{
   // Do stuff
}

有关详细信息,请参阅: http://msdn.microsoft.com/en-us/library/system.windows.uielement.touchdown(v=vs.110).aspxhttp://msdn.microsoft.com/en-us/library/ms754010(v=vs.110).aspx

答案 1 :(得分:0)

触摸*事件会让你触摸。指针*将为您提供触摸,鼠标和手写笔。

使用*向下来了解触摸何时发生故障,以及*了解它何时上升。如果您想在触摸关闭时重复执行某些操作,请在* Down上创建DispatcherTimer并在* Up上停止