void OnTouchEffectAction(object sender, TouchActionEventArgs args) { switch (args.Type) { case TouchActionType.Pressed: if (!inProgressPolylines.ContainsKey(args.Id)) { Color strokeColor = (Color)typeof(Color).GetRuntimeField(colorPicker.Items[colorPicker.SelectedIndex]).GetValue(null); float strokeWidth = ConvertToPixel(new float[] { 1, 2, 5, 10, 20 }[widthPicker.SelectedIndex]); FingerPaintPolyline polyline = new FingerPaintPolyline { StrokeColor = strokeColor, StrokeWidth = strokeWidth }; polyline.Path.MoveTo(ConvertToPixel(args.Location)); inProgressPolylines.Add(args.Id, polyline); canvasView.InvalidateSurface(); } break; case TouchActionType.Moved: if (inProgressPolylines.ContainsKey(args.Id)) { FingerPaintPolyline polyline = inProgressPolylines[args.Id]; polyline.Path.LineTo(ConvertToPixel(args.Location)); canvasView.InvalidateSurface(); } break; case TouchActionType.Released: if (inProgressPolylines.ContainsKey(args.Id)) { completedPolylines.Add(inProgressPolylines[args.Id]); inProgressPolylines.Remove(args.Id); canvasView.InvalidateSurface(); } break; case TouchActionType.Cancelled: if (inProgressPolylines.ContainsKey(args.Id)) { inProgressPolylines.Remove(args.Id); canvasView.InvalidateSurface(); } break; } }
void OnTouchEffectAction(object sender, TouchActionEventArgs args) { switch (args.Type) { case TouchActionType.Pressed: if (!inProgressPolylines.ContainsKey(args.Id)) { //Color strokeColor = (Color)typeof(Color).GetRuntimeField(colorPicker.Items[colorPicker.SelectedIndex]).GetValue(null); //float strokeWidth = ConvertToPixel(new float[] { 1, 2, 5, 10, 20 }[widthPicker.SelectedIndex]); //FingerPaintPolyline polyline = new FingerPaintPolyline //{ // StrokeColor = strokeColor, // StrokeWidth = strokeWidth //}; //polyline.Path.MoveTo(ConvertToPixel(args.Location)); //inProgressPolylines.Add(args.Id, polyline); touchPoint = args.Location; touchPoint1 = ConvertToPixel(args.Location); txt.Text = ""; txt.TextChanged += Txt_TextChanged; txt.WidthRequest = 300; txt.HeightRequest = 40; txt.VerticalOptions = LayoutOptions.Start; txt.HorizontalOptions = LayoutOptions.Start; //txt.BackgroundColor = Color.Yellow; txt.InputTransparent = true; txt.TextColor = Color.White; txt.BackgroundColor = Color.Transparent; gridCanvas.Children.Add(txt, 0, 0); //gridCanvas.Children[1]. gridCanvas.Children[1].TranslationX = args.Location.X; //ConvertToPixel(args.Location).X; gridCanvas.Children[1].TranslationY = args.Location.Y; //ConvertToPixel(args.Location).Y; //canvasView.InputTransparent = true; gridCanvas.Children[1].Focus(); gridCanvas.RowDefinitions[0].Height = GridLength.Star; //gridCanvas.RowDefinitions[1].Height = GridLength.Star; canvasView.InvalidateSurface(); } break; case TouchActionType.Moved: if (inProgressPolylines.ContainsKey(args.Id)) { FingerPaintPolyline polyline = inProgressPolylines[args.Id]; polyline.Path.LineTo(ConvertToPixel(args.Location)); canvasView.InvalidateSurface(); } break; case TouchActionType.Released: if (inProgressPolylines.ContainsKey(args.Id)) { completedPolylines.Add(inProgressPolylines[args.Id]); inProgressPolylines.Remove(args.Id); canvasView.InvalidateSurface(); } break; case TouchActionType.Cancelled: if (inProgressPolylines.ContainsKey(args.Id)) { inProgressPolylines.Remove(args.Id); canvasView.InvalidateSurface(); } break; } }