private void Canvas_Draw()

in ExampleGallery/StrokeStyles.xaml.cs [46:139]


        private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            strokeStyle.StartCap = StartCap;
            strokeStyle.EndCap = EndCap;
            strokeStyle.DashStyle = DashStyle;
            strokeStyle.DashCap = DashCap;
            strokeStyle.LineJoin = LineJoin;

            var ds = args.DrawingSession;

            var width = (float)sender.ActualWidth;
            var height = (float)sender.ActualHeight;

            var col1Left = width * 0.1f;
            var col1Right = width * 0.4f;
            var col2Left = width * 0.6f;
            var col2Right = width * 0.9f;

            var row1Top = height * 0.1f;
            var row1Bottom = height * 0.4f;
            var row2Top = height * 0.6f;
            var row2Bottom = height * 0.9f;

            //
            // Draw hairlines showing the start/end points of the line.  
            // This helps demonstrate the behavior of start/end cap.
            //
            ds.DrawLine(
                col1Left,
                row1Top,
                col1Left,
                row1Bottom,
                Colors.Aqua,
                1.0f,
                this.hairlineStrokeStyle);

            ds.DrawLine(
                col1Right,
                row1Top,
                col1Right,
                row1Bottom,
                Colors.Aqua,
                1.0f,
                this.hairlineStrokeStyle);

            //
            // Draw the demo shapes with the chosen stroke style
            //
            var strokeWidth = (float)Math.Max(5, Math.Min(30, width / 50));

            ds.DrawLine(
                col1Left, 
                (row1Top + row1Bottom) / 2,
                col1Right,
                (row1Top + row1Bottom) / 2,
                Colors.Green,
                strokeWidth,
                this.strokeStyle);

            ds.DrawRectangle(
                new Rect(new Point(col2Left, row1Top), new Point(col2Right, row1Bottom)),
                Colors.Green,
                strokeWidth,
                this.strokeStyle);

            ds.DrawRoundedRectangle(
                new Rect(new Point(col1Left, row2Top), new Point(col1Right, row2Bottom)),
                width * 0.1f,
                height * 0.1f,
                Colors.Green,
                strokeWidth,
                this.strokeStyle);

            ds.DrawEllipse(
                (col2Left + col2Right) / 2,
                (row2Top + row2Bottom) / 2,
                (col2Right - col2Left) / 2,
                (row2Bottom - row2Top) / 2,
                Colors.Green,
                strokeWidth,
                this.strokeStyle);

            //
            // Explain what is going on if this combination of properties leaves dots invisible
            //
            bool hasDots = DashStyle == CanvasDashStyle.Dot ||
                           DashStyle == CanvasDashStyle.DashDot ||
                           DashStyle == CanvasDashStyle.DashDotDot;

            if (hasDots && DashCap == CanvasCapStyle.Flat)
            {
                ds.DrawText("Dots have zero size when DashCap = CanvasCapStyle.Flat", col1Left, 0, Colors.White);
            }
        }