コード例 #1
0
        private void canvasControl_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (pointerDrag == null)
            {
                return; // Nothing to do
            }
            // Commit the shape into the document
            CanvasSvgNamedElement newChild = null;

            if (CurrentShapeType == ShapeType.Rectangle)
            {
                Rect r = pointerDrag.GetRectangle();
                newChild = svgDocument.Root.CreateAndAppendNamedChildElement("rect");
                newChild.SetFloatAttribute("x", (float)r.Left);
                newChild.SetFloatAttribute("y", (float)r.Top);
                newChild.SetFloatAttribute("width", (float)r.Width);
                newChild.SetFloatAttribute("height", (float)r.Height);
            }
            else if (CurrentShapeType == ShapeType.Ellipse)
            {
                var ellipse = pointerDrag.GetEllipse();
                newChild = svgDocument.Root.CreateAndAppendNamedChildElement("ellipse");
                newChild.SetFloatAttribute("cx", ellipse.CenterX);
                newChild.SetFloatAttribute("cy", ellipse.CenterY);
                newChild.SetFloatAttribute("rx", ellipse.RadiusX);
                newChild.SetFloatAttribute("ry", ellipse.RadiusY);
            }
            else if (CurrentShapeType == ShapeType.Circle)
            {
                var circle = pointerDrag.GetCircle();
                newChild = svgDocument.Root.CreateAndAppendNamedChildElement("circle");
                newChild.SetFloatAttribute("cx", circle.Center.X);
                newChild.SetFloatAttribute("cy", circle.Center.Y);
                newChild.SetFloatAttribute("r", circle.Radius);
            }
            else if (CurrentShapeType == ShapeType.Line)
            {
                var start = pointerDrag.StartLocation.ToVector2();
                var end   = pointerDrag.CurrentLocation.ToVector2();
                newChild = svgDocument.Root.CreateAndAppendNamedChildElement("line");
                newChild.SetFloatAttribute("x1", start.X);
                newChild.SetFloatAttribute("y1", start.Y);
                newChild.SetFloatAttribute("x2", end.X);
                newChild.SetFloatAttribute("y2", end.Y);
            }
            newChild.SetColorAttribute("fill", colorPicker.CurrentColor);
            newChild.SetColorAttribute("stroke", Colors.Black);
            newChild.SetFloatAttribute("stroke-width", 4.0f);

            pointerDrag = null;
            canvasControl.Invalidate();
        }
コード例 #2
0
 private static void UseDefaultStroke(CanvasSvgNamedElement rect)
 {
     rect.SetColorAttribute("stroke", Colors.Black);
     rect.SetFloatAttribute("stroke-width", 5);
 }