private static void refreshGraph(MainWindow win) { Canvas canvas = win.DrawArea; canvas.Children.Clear(); double height = win.DrawArea.ActualHeight; double width = win.DrawArea.ActualWidth; double angleStep = 4 * Math.PI / width; drawAxes(win); double lastX = 0; double lastY = win.CoefA * win.FunctionProperty(-2 * Math.PI * win.CoefB); for (int i = 1; i < width; i++) { double x = -2 * Math.PI + i * angleStep; ComboItemDelegate function = win.FunctionProperty; double value = (height / 2) * win.CoefA * function(x * win.CoefB); double y = height / 2 - value; Line line = new Line(); line.Stroke = Brushes.Black; line.X1 = i; line.Y1 = lastY; line.X2 = i + 1; line.Y2 = y; canvas.Children.Add(line); lastX = i + 1; lastY = y; } }
public MainWindow() { InitializeComponent(); for (int i = -10; i < 0; i++) { ABox.Items.Add(i); } for (int i = 1; i <= 10; i++) { ABox.Items.Add(i); BBox.Items.Add(i); if (i == 1) { ABox.SelectedIndex = 10 + i; BBox.SelectedIndex = 10 + i; } } /* ABox.SelectedItem = 1; * BBox.SelectedItem = 1;*/ ComboItemDelegate sin = Math.Sin; ComboItemDelegate cos = Math.Cos; ComboBoxItem sinItem = new ComboBoxItem(); sinItem.Tag = sin; sinItem.Content = "Sin"; ComboBoxItem cosItem = new ComboBoxItem(); cosItem.Tag = cos; cosItem.Content = "Cos"; FunBox.Items.Add(sinItem); FunBox.Items.Add(cosItem); FunBox.SelectedIndex = 0; }
private void FunBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboItemDelegate sin = Math.Sin, cos = Math.Cos; FunctionProperty = (FunBox.SelectedIndex == 0 ? sin : cos); }