首页 > 代码库 > Windows Phone 8.1开发:触控和指针事件2
Windows Phone 8.1开发:触控和指针事件2
原文出自:http://www.bcmeng.com/windows-phone-touch1/
请在此输入内容(想死啊,写了一个小时,直接没保存不小心删掉了。那就简单说说吧)Pointer事件有以下事件:
- PointerCanceled
- PointerEntered
- PointerExited
- PointerMoved
- PointerPressed
- PointerReleased
- PointerCaptureLost
其引发顺序如下:
当点击时:即Tap事件引发的触摸和指针事件顺序如下:
12:4:8-PointerEntered事件发生
12:4:8-PointerPressed事件发生
12:4:8-ManipulationStarting事件发生
12:4:8-PointerMoved事件发生
12:4:8-PointerMoved事件发生
12:4:8-PointerReleased事件发生
12:4:8-Tapped事件发生
12:4:8-PointerExited事件发生
当长按时:即righttap事件引发的触摸和指针事件如下:
12:6:15-PointerEntered事件发生
12:6:15-PointerPressed事件发生
12:6:15-ManipulationStarting事件发生
12:6:15-PointerMoved事件发生
12:6:15-PointerMoved事件发生
12:6:16-PointerReleased事件发生
12:6:16-RightTapped事件发生
12:6:16-PointerExited事件发生
关于各个指针事件的含义,大家根据名称也能意会,小梦刚才写的很详细,只不过没了,大家就直接参考MSDN文档吧。不过要注意:
每当触控操作产生 PointerPressed 事件时,该事件紧接在 PointerEntered 事件之后,并且所有事件数据对于这两个事件具有相同的信息(相同的指针 ID、相同的位置等)
PointerPressed和PointerReleased事件并不总是成对出现的。您的应用程序应该倾听并处理可能得出一个指向下的动作(比如无论如何PointerExited,PointerCanceled和PointerCaptureLost)。
下面演示一个通过指针事件和LIne控件实现的笔触画图实例:
首先定义一个画布:
<Canvas Name=”canvas”Background=”Transparent”PointerPressed=”canvas_PointerPressed”PointerMoved=”canvas_PointerMoved”></Canvas>
后台逻辑:
private Point currentPoint; //最新的,当前的点private Point oldPoint;//上一个点private void canvas_PointerPressed(object sender, PointerRoutedEventArgs e){currentPoint = e.GetCurrentPoint(canvas).Position;oldPoint = currentPoint;}private void canvas_PointerMoved(object sender, PointerRoutedEventArgs e){currentPoint = e.GetCurrentPoint(canvas).Position;Line line = new Line() { X1 = currentPoint.X, Y1 = currentPoint.Y, X2 = oldPoint.X, Y2 = oldPoint.Y };line.Stroke = new SolidColorBrush(Colors.Red);line.StrokeThickness = 5;line.StrokeLineJoin = PenLineJoin.Round;line.StrokeStartLineCap = PenLineCap.Round;line.StrokeEndLineCap = PenLineCap.Round;this.canvas.Children.Add(line);oldPoint = currentPoint;}
如果对Line的属性不清楚,请参考MSDN:http://msdn.microsoft.com/library/windows/apps/system.windows.shapes.shape(v=vs.105).aspx
运行效果如下:
windows phone触控和指针源代码下载;点我下载哦!
Windows Phone 8.1开发:触控和指针事件2