Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how can we draw square wave or pulse train in WPF? I have read on the internet .. but could not find any solution.. the only solution I found that was close was using sine function.. that was using frequency... But i do not have any frequency... i have an array of integers.. and i want to draw square wave from those integers.. As those integers represent the transitional state of the wave...

What I have tried:

ImageShack - gr1.PNG[^]

Line redLine = new Line();

            redLine.X1 = 100;

            redLine.Y1 = 0;

            redLine.X2 = 200;

            redLine.Y2 = 0;
            SolidColorBrush redBrush = new SolidColorBrush();

            redBrush.Color = Colors.Red;
            redLine.StrokeThickness = 4;

            redLine.Stroke = redBrush;
            myCanvas.Children.Add(redLine);


            Line Line = new Line();

            Line.X1 = 200;

            Line.Y1 = 0;

           Line.X2 = 200;

            Line.Y2 = 150;
            SolidColorBrush Brush = new SolidColorBrush();

          Brush.Color = Colors.Black;
         Line.StrokeThickness = 4;

            Line.Stroke = Brush;
            myCanvas.Children.Add(Line);

            Line line = new Line();

            line.X1 = 200;

            line.Y1 = 150;

            line.X2 = 400;

            line.Y2 = 150;
            SolidColorBrush brush = new SolidColorBrush();

            brush.Color = Colors.Orange;
            line.StrokeThickness = 4;

            line.Stroke = Brush;
            myCanvas.Children.Add(line);

            Line line4 = new Line();

            line4.X1 = 400;

            line4.Y1 = 150;

            line4.X2 = 400;

            line4.Y2 = 500;
            SolidColorBrush brush4 = new SolidColorBrush();

            brush4.Color = Colors.Blue;
            line4.StrokeThickness = 4;

            line4.Stroke = Brush;
            myCanvas.Children.Add(line4);
Posted
Updated 27-Jun-18 4:34am
v5
Comments
Richard MacCutchan 22-Jun-18 11:09am    
Frequency values are just numbers, the same as integers. Drawing a wave is just a matter of plotting the values on a graph. Create your axes and then calculate the x and y positions based on your data.

1 solution

The only solution is to use a canvas. You could possibly create a custom canvas that would include a way to create such a graph. Lots of examples on the web, and obviously you have looked. Here is one:
tp://csharphelper.com/blog/2014/09/draw-graph-wpf-c/[^]. If I was to do it I would probably create a custom control the inherits from the Canvas, and have dependency properties for Max, Min, increment, and for the function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900