/* * 获取控件所在的区域算法 */ PressPointLocation GetPointLocation(Point point) { PressPointLocation location = PressPointLocation.None; double tempwidth = ActualWidth / 3; if (point.X < tempwidth) { location |= PressPointLocation.Left; } else if (point.X > tempwidth * 2) { location |= PressPointLocation.Right; } else { location |= PressPointLocation.XCenter; } double tempheight = ActualHeight / 3; if (point.Y < tempheight) { location |= PressPointLocation.Top; } else if (point.Y > tempheight * 2) { location |= PressPointLocation.Bottom; } else { location |= PressPointLocation.YCenter; } Debug.WriteLine(location.ToString()); return(location); }
/* * 按下时的事件处理,两个步骤 * 1、首先判断当前按下去的位置在控件的那个区域(控件共分为9个区域,详见PressPointLocation定义) * 2、根据按下去的位置,对控件做不同的效果 */ protected override void OnPointerPressed(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { // 获得当前区域位置 PressPointLocation location = GetPointLocation(e.GetCurrentPoint(this).Position); // 开始对控件做效果处理 if (location == (PressPointLocation.Left | PressPointLocation.YCenter)) {// 左中 projection.RotationY = angle; projection.CenterOfRotationX = 1; } else if (location == (PressPointLocation.Left | PressPointLocation.Top)) {// 左上 projection.RotationX = -angle; projection.RotationY = angle; projection.CenterOfRotationX = 1; projection.CenterOfRotationY = 1; } else if (location == (PressPointLocation.Top | PressPointLocation.XCenter)) {// 上中 projection.RotationX = -angle * 2; projection.CenterOfRotationY = 1; } else if (location == (PressPointLocation.Right | PressPointLocation.Top)) {// 右上 projection.RotationY = projection.RotationX = -angle; projection.CenterOfRotationX = 0; projection.CenterOfRotationY = 1; } else if (location == (PressPointLocation.Right | PressPointLocation.YCenter)) {// 右中 projection.RotationY = -angle; projection.CenterOfRotationX = 0; } else if (location == (PressPointLocation.Right | PressPointLocation.Bottom)) {// 右下 projection.RotationX = angle; projection.RotationY = -angle; projection.CenterOfRotationX = 0; projection.CenterOfRotationY = 0; } else if (location == (PressPointLocation.Bottom | PressPointLocation.XCenter)) {// 下中 projection.RotationX = angle * 2; projection.CenterOfRotationY = 0; } else if (location == (PressPointLocation.Left | PressPointLocation.Bottom)) {// 左下 projection.RotationY = projection.RotationX = angle; projection.CenterOfRotationX = 1; projection.CenterOfRotationY = 1; } else if (location == (PressPointLocation.XCenter | PressPointLocation.YCenter)) {// 正中 CompositeTransform transform = RenderTransform as CompositeTransform; transform.CenterX = ActualWidth / 2; transform.CenterY = ActualHeight / 2; transform.ScaleX = 0.9; transform.ScaleY = 0.9; } }