2016-04-22 11 views
1

キャンバスにシェイプを描きたいので、シェイプとして扱う必要があります。キャンバスから選択、移動、削除することができます。これは、アルファベットや数字やサークルにすることができます。これは、MSPaintのようなキャンバスに描画することができます。メトロスタイルのアプリでink-managerを使ってキャンバスを描画する方法

UWP(https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.inking.inkmanager.aspx)にはお勧めできないので、私はインクマネージャーを使いたくありません。 これは、インクマネージメントを使用せずに行うことができますか? はここにポインタ上のコードがポインタリリースイベントにキャンバス

void AddPencil(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) 
    { 
     if (PenID != 0) 
     { 
      PointerPoint pt = e.GetCurrentPoint(_drawCanvas); 

      CurrentContactPoint = pt.Position; 
      X1 = PreviousContactPoint.X; 
      Y1 = PreviousContactPoint.Y; 
      X2 = CurrentContactPoint.X; 
      Y2 = CurrentContactPoint.Y; 

      if (Distance(X1, Y1, X2, Y2) > 2.0) 
      { 
       Line line = new Line() 
        { 
         X1 = X1, 
         Y1 = Y1, 
         X2 = X2, 
         Y2 = Y2, 
         StrokeThickness = 5, 
         Stroke = new SolidColorBrush(Colors.Violet) 
        }; 
       _drawCanvas.Children.Add(line); 
      } 


      PathFigure pthFigure = new PathFigure(); 
      pthFigure.StartPoint = PreviousContactPoint; 
      BezierSegment bzSeg = new BezierSegment(); 
      Point p1 = new Point(); 
      p1.X = X1; 
      p1.Y = Y1; 
      Point p2 = new Point(); 
      p2.X = X2; 
      p2.Y = Y2; 
      bzSeg.Point1 = p1; 
       bzSeg.Point2 =p2; 
       bzSeg.Point3 = CurrentContactPoint; 

      PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); 
      myPathSegmentCollection.Add(bzSeg); 

      pthFigure.Segments = myPathSegmentCollection; 

      if (pthFigureCollection == null) 
       pthFigureCollection = new PathFigureCollection(); 
      pthFigureCollection.Add(pthFigure); 
      PreviousContactPoint = CurrentContactPoint; 
     } 
    } 

とコードの上に移動されます。

List<UIElement> uielementscolctn = new List<UIElement>(); 
      foreach(var item in _drawCanvas.Children) 
      { 
       var x = item as Line; 

       uielementscolctn.Add(x); 
      } 
      foreach (var uielenmt in uielementscolctn) 
      { 
       _drawCanvas.Children.Remove(uielenmt); 
      } 
      PathGeometry pthGeometry = new PathGeometry(); 
      pthGeometry.Figures = pthFigureCollection; 
      arcPath = new Path(); 
      arcPath.Tapped+=arcPath_Tapped; 
      translateTransform_ = new TranslateTransform(); 
      translateTransform_.X = 0.0; 
      translateTransform_.Y = 0.0; 

      scaleTransform_ = new ScaleTransform(); 
      scaleTransform_.ScaleX = 0.0; 
      scaleTransform_.ScaleY = 0.0; 




      arcPath.ManipulationMode = MarkupBase.manipulationMode_; 

      arcPath.ManipulationStarted += arcPath_ManipulationStarted; 
      arcPath.ManipulationDelta += arcPath_ManipulationDelta; 
      arcPath.Stroke = new SolidColorBrush(Colors.Violet); 
      arcPath.StrokeThickness = 5; 

      arcPath.Data = pthGeometry; 

      originalBounds_ = arcPath.Data.Bounds; 
      _drawCanvas.Children.Add(arcPath); 
      arcPath.Data.Transform = tgroup; 
      PenID = 0; 
      Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 1); 
      pthFigureCollection = null; 

これまでにarcPath.Data.Transform = tgroupとして値を変更したため、パスの形状を操作できません。経路のデータ境界はゼロになる。

答えて

0

InkCanvasを見てみましたか?これはUWPアプリでも、あなたが望むことをする方法です。

https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.inkcanvas.aspx

+0

InkCanvasはwindows8.1アプリケーションでは使用できません。パス(形状)を操作できますか? – user1151378

+0

私のアイデアは、すべてのストークをパスとして作成し、そのパスの操作操作を行います。 – user1151378

+0

なぜWindows 8.1についてお話ししていますか?ターゲットOSですか? –

0

代わりにベジェセグメントのポリラインセグメントを使用します。

関連する問題