Inheritance: BaseViewModel
Exemple #1
0
        public void Remove(GraphItemViewModel exp)
        {
            listOfGraphs.Remove(exp);

            view.Graphs = listOfGraphs.AsReadOnly();
        }
Exemple #2
0
        private void DrawFunc(GraphItemViewModel graph)
        {
            var exp = graph.Expression;
            var geometry = new StreamGeometry();

            using (var context = geometry.Open())
            {
                bool startFlag = true;
                double y;
                double tempY;
                for (double x = -centerX / cm; x <= (currentWidth - centerX) / cm; x += 0.03 * slider.Value)
                {
                    parameters.Parameters["x"] = x;
                    y = (double)exp.Calculate(parameters);

                    tempY = centerY - (y * cm);
                    if (double.IsNaN(y) || tempY < 0 || tempY > currentHeight)
                    {
                        startFlag = true;
                    }
                    else
                    {
                        if (startFlag)
                        {
                            context.BeginFigure(new Point(centerX + (x * cm), tempY), false, false);
                            startFlag = false;
                        }

                        context.LineTo(new Point(centerX + (x * cm), tempY), true, false);
                    }
                }
            }

            geometry.Freeze();

            var funcVisual = new DrawingVisual();
            var pen = new Pen(Brushes.Red, 1);
            pen.Freeze();
            using (DrawingContext context = funcVisual.RenderOpen())
            {
                context.DrawGeometry(Brushes.Red, pen, geometry);
            }
            graph.Visual = funcVisual;
            canvas.AddVisual(funcVisual);
        }