Esempio n. 1
0
        private bool GetArea(int s, bool isUp, out LineAndAreaShape area, out Point ofPt)
        {
            var isNew = false;

            ofPt = new Point();

            if (_areas.Count <= s)
            {
                var path = new Path();
                BindingOperations.SetBinding(path, Shape.StrokeProperty,
                                             new Binding {
                    Path = new PropertyPath("Stroke"), Source = this
                });
                BindingOperations.SetBinding(path, Shape.FillProperty,
                                             new Binding {
                    Path = new PropertyPath("Fill"), Source = this
                });
                BindingOperations.SetBinding(path, Shape.StrokeThicknessProperty,
                                             new Binding {
                    Path = new PropertyPath("StrokeThickness"), Source = this
                });
                BindingOperations.SetBinding(path, VisibilityProperty,
                                             new Binding {
                    Path = new PropertyPath("Visibility"), Source = this
                });
                BindingOperations.SetBinding(path, Panel.ZIndexProperty,
                                             new Binding {
                    Path = new PropertyPath(Panel.ZIndexProperty), Source = this
                });
                BindingOperations.SetBinding(path, Shape.StrokeDashArrayProperty,
                                             new Binding {
                    Path = new PropertyPath(StrokeDashArrayProperty), Source = this
                });
                var geometry = new PathGeometry();
                area = new LineAndAreaShape(new PathFigure(), path);
                geometry.Figures.Add(area.Figure);
                path.Data = geometry;
                _areas.Add(area);
                Chart.DrawMargin.Children.Add(path);
                isNew = true;
                if (isUp)
                {
                    if (Chart.Invert)
                    {
                        ofPt = new Point(0, Methods.GetUnitWidth(AxisTags.Y, Chart, ScalesYAt) * .5);
                        Canvas.SetTop(path, ofPt.Y);
                    }
                    else
                    {
                        ofPt = new Point(Methods.GetUnitWidth(AxisTags.X, Chart, ScalesXAt) * .5, 0);
                        Canvas.SetLeft(path, ofPt.X);
                    }
                }
            }
            else
            {
                area = _areas[s];
                if (isUp)
                {
                    if (Chart.Invert)
                    {
                        ofPt = new Point(0, Methods.GetUnitWidth(AxisTags.Y, Chart, ScalesYAt) * .5);
                        Canvas.SetTop(area.Path, ofPt.Y);
                    }
                    else
                    {
                        ofPt = new Point(Methods.GetUnitWidth(AxisTags.X, Chart, ScalesXAt) * .5, 0);
                        Canvas.SetLeft(area.Path, ofPt.X);
                    }
                }
            }
            return(isNew);
        }