I am trying to design a GUI for an oscilloscope as a part of my MTech project. While I have no problem setting the scale after taking the input from the user for the X and Y axes, I am facing trouble displaying the waveform. Right now, I am using a PolyLine
. Every time a new value is received, the disp
array is updated, the current contents are cleared and the wave is displayed.
This is the piece of code I wrote, just to add elements and clear the Grid
.
public partial class MainWindow : Window
{
int[] disp = new int[500];
private int x = 0;
Polyline Wave=new Polyline();
public MainWindow()
{
InitializeComponent();
}
private void SetValue_Click(object sender, RoutedEventArgs e)
{
x++;
SetValue_disp(x);
}
private void SetValue_disp(int x)
{
for (int i = 0; i < disp.Length; i++)
disp[i] = x;
}
private void Clear_Click(object sender, RoutedEventArgs e)
{
TheDisp.Children.Clear();
}
private void Apply_Click(object sender, RoutedEventArgs e)
{
Wave.StrokeThickness = 2;
int i = 0;
foreach (int isp in disp)
{
Wave.Points.Add(new Point(i, isp));
i++;
}
TheDisp.Children.Add(Wave);
}
}
I have the following doubts 1) Why is the element not displayed when it click on the apply button 2) There has to be a better way than to clear the entire grid and re-displaying the entire data all over again
Any form of help appreciated.