1

我正在为 windows phone 8 开发一个应用程序,并希望将图像拖放到指定位置。如果位置错误,那么我想将其设置回初始位置。

我正在使用此代码来实现此功能。

void img1_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
    {

        FrameworkElement Elem = sender as FrameworkElement;
        double top = Elem.Margin.Top;
        double left = Elem.Margin.Left;

      if (top>249+110/ 2 && left > 212+212/ 2)
      {
          System.Diagnostics.Debug.WriteLine("Top{0},Left:{1}", top, left);
      }
      else
      {
          Elem.Margin = new Thickness(30, 212, 0, 0);
      }
    }

    void img1_ManipulationDelta(object sender, ManipulationDeltaEventArgs args)
    {

        FrameworkElement Elem = sender as FrameworkElement;
        GeneralTransform gt = ContentPanel.TransformToVisual(Elem);
        Point currentPos = gt.Transform(new Point(0, 0));
        Elem.Margin = new Thickness(args.DeltaManipulation.Translation.X - currentPos.X, args.DeltaManipulation.Translation.Y - currentPos.Y, 0, 0);

    }

是否有任何内置方法可以判断适当矩形的交集?在此处输入图像描述

4

0 回答 0