C# 如何在Windows 8 metro应用程序中检测多点触摸操作?

C# 如何在Windows 8 metro应用程序中检测多点触摸操作?,c#,multi-touch,windows-8,windows-runtime,microsoft-metro,C#,Multi Touch,Windows 8,Windows Runtime,Microsoft Metro,我现在正在开发一个metro应用程序,希望能够启用多点触控。我浏览过谷歌,但似乎找不到任何支持它的API。有人能告诉我在Windows 8 Metro应用程序中支持多点触摸操作的正确方向吗?你到底想做什么?每个UI元素上都有触摸、指针(围绕触摸/鼠标/触笔的抽象)和操作事件看看这篇文章 来自post的示例脚本: <script> function handleEvent(event) { var currentPointers = event.getPointerList()

我现在正在开发一个metro应用程序,希望能够启用多点触控。我浏览过谷歌,但似乎找不到任何支持它的API。有人能告诉我在Windows 8 Metro应用程序中支持多点触摸操作的正确方向吗?

你到底想做什么?每个UI元素上都有触摸、指针(围绕触摸/鼠标/触笔的抽象)和操作事件

看看这篇文章

来自post的示例脚本:

<script>
function handleEvent(event) {
    var currentPointers = event.getPointerList();
    if (currentPointers.length == 1) {
        event.target.style.backgroundColor = "red";
        } else {
        event.target.style.backgroundColor = "green"; //multiple touch points are used
        }
    }
document.getElementById("foo").addEventListener("MSPointerMove", handleEvent, false);
</script>

功能handleEvent(事件){
var currentPointers=event.getPointerList();
如果(currentPointers.length==1){
event.target.style.backgroundColor=“红色”;
}否则{
event.target.style.backgroundColor=“绿色”//使用多个接触点
}
}
document.getElementById(“foo”).addEventListener(“MSPointerMove”,handleEvent,false);

在JavaScript中,您可以使用事件指针ID来检测多个触摸输入。此标识符为每个新输入提供了一个id。当您想通过手指移动获得多点触碰时,您可以使用MSPointerMove事件和此id。我正在使用jQuery,但绑定和取消绑定功能无法工作,因为事件未附加。您必须使用普通Javascript才能使多点触摸正常工作:

var pointerId=0; 
//add a Eventlistner to the Down Event (compareable to mousedown and touchstart)
$('#button1')[0].addEventListener("MSPointerDown",function(event) {
       pointerId=event.pointerId; //save the pointerId to a (in this case) global var
       window.addEventListener("MSPointerMove", moveHandler, false);
       //The handlers should also be removed on MSPointerUp. 
       //You can't use jQuery unbind for this, it dosn't work.
       //use window.removeListener("MSPointerMove",moveHandler);
},false);

//define the moveHandler and check the pointer ID 
var moveHandler = function(event) {
      if(pointerId==event.pointerId) {
            //If the pointerId is the same, the moving comes from one finger
            //For example we can move the button with the finger
            $("#button1").css({'top':event.pageY,'left':event.pageX,'position':'absolute'});
      }
}
下面是一个完整的示例,它使用foreach将事件处理程序附加到多个按钮。如果你启动这个应用程序,你将得到4个正方形,你可以用多个手指移动

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>App1</title>

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.1.0.RC/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.1.0.RC/js/base.js"></script>
    <script src="//Microsoft.WinJS.1.0.RC/js/ui.js"></script>

    <!-- App1 references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>
    <script src="js/jquery.js"></script>
    <script>
        function start() {
            //add a Eventlistner to the Down Event (compareable to mousedown and touchstart)
            $(".button").each(function (i, element) {
                var pointerId = 0;
                $(element)[0].addEventListener("MSPointerDown", function (event) {
                    pointerId = event.pointerId; //save the pointerId to a (in this case) global var
                    window.addEventListener("MSPointerMove", moveHandler, false);
                }, false);

                //PointerUp handler
                window.addEventListener("MSPointerUp", upHandler, false);

                //define the moveHandler and check the pointer ID 
                var moveHandler = function (event) {
                    if (pointerId == event.pointerId) {
                        $(element).css({ "top": event.pageY-50, "left":event.pageX-50 });
                    }
                }

                //remove the moveHandler on PointerUp
                var upHandler = function (event) {
                    if (pointerId == event.pointerId) {
                        window.removeListener("MSPointerMove", moveHandler);
                    }
                }
            });
        }
    </script>
</head>
<body>
    <div class="button" style="width:100px;height:100px;background-color:#F80;position:absolute;"></div>
    <div class="button" style="width:100px;height:100px;background-color:#08F;position:absolute;"></div>
    <div class="button" style="width:100px;height:100px;background-color:#fff;position:absolute;"></div>
    <div class="button" style="width:100px;height:100px;background-color:#4cff00;position:absolute;"></div>
</body>
</html>

附件1
函数start(){
//将Eventlistner添加到Down事件(可与mousedown和touchstart进行比较)
$(“.button”)。每个(函数(i,元素){
var pointerId=0;
$(元素)[0]。addEventListener(“MSPointerDown”,函数(事件){
pointerId=event.pointerId;//将pointerId保存到(在本例中)全局变量
addEventListener(“MSPointerMove”,moveHandler,false);
},假);
//指针处理器
addEventListener(“MSPointerUp”,upHandler,false);
//定义moveHandler并检查指针ID
var moveHandler=函数(事件){
if(pointerId==event.pointerId){
$(element.css({“top”:event.pageY-50,“left”:event.pageX-50});
}
}
//删除PointerUp上的moveHandler
var upHandler=函数(事件){
if(pointerId==event.pointerId){
removeListener(“MSPointerMove”,moveHandler);
}
}
});
}

使用这种方法,您可以同时使用4个手指

尝试操纵任何控件的增量

您可以通过确定任何操纵事件args的Scale属性来确定触摸是否为多点触摸

 private void AssetMap_ManipulationDelta_1(object sender, ManipulationDeltaRoutedEventArgs e)
        {

            if (e.Cumulative.Scale != 1)
            {

//indicates that it is multitouch

}

希望它能帮助您……

您试过这个吗?getPointerList似乎不是事件负载的一部分…:\