Exemple #1
0
        private void BtnCalculate_Click(object?sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            if (double.TryParse(tbStart.Text, out double xStart) &&
                double.TryParse(tbEnd.Text, out double xEnd) &&
                double.TryParse(tbStep.Text, out double step) &&
                xStart < xEnd && step > 0)
            {
                spValues.Children.Clear();
                double x = xStart;
                do
                {
                    var dp = new DockPanel();
                    dp.Children.Add(new TextBlock()
                    {
                        Text          = x.ToString(),
                        Width         = window.MinWidth / 2,
                        TextAlignment = Avalonia.Media.TextAlignment.Center
                    });
                    dp.Children.Add(new TextBlock()
                    {
                        Text          = Math.Round(rpn.GetNewRpnWithSetVariable(x).Calculate(), 3).ToString(),
                        Width         = window.MinWidth / 2,
                        TextAlignment = Avalonia.Media.TextAlignment.Center
                    });
                    spValues.Children.Add(dp);

                    x = Math.Round(x + step, 3);
                } while (x <= xEnd);
            }
        }
Exemple #2
0
        //Изменение отображаемого значения графика функции в зависимости от позиции мыши
        private static void GraphCanvas_PointerMoved(object?sender, PointerEventArgs e)
        {
            if (!mousePressed && expression != null)
            {
                TextBlock tbXCoord = TheMainWindow.FindControl <TextBlock>("tbXCoord");
                TextBlock tbYCoord = TheMainWindow.FindControl <TextBlock>("tbYCoord");
                var       canvas   = (Canvas)sender;

                double x = (e.GetPosition(canvas).X - GraphWidth / 2 - Offset.X) * Zoom;
                double y = rpn.GetNewRpnWithSetVariable(x).Calculate();

                tbXCoord.Text = "x: " + Math.Round(x, 2).ToString();
                tbYCoord.Text = "f(x): " + Math.Round(y, 2).ToString();
            }
        }