Exemplo n.º 1
0
        protected UIElement RenderElement(List <UIElement> objects, IPlotElement pe, DataSeries ds, RenderContext rc, ShapeStyle shapeStyle, DataPoint dp)
        {
            DataTemplate pointLabelTemplate = ds.PointLabelTemplate;
            PlotElement  element            = pe as PlotElement;

            if (((ItemNames != null) && (dp.PointIndex < ItemNames.Length)) && (ItemNames[dp.PointIndex] != null))
            {
                dp.Name = ItemNames[dp.PointIndex].ToString();
            }
            FrameworkElement lbl  = null;
            Line             line = null;

            if (pointLabelTemplate != null)
            {
                lbl             = pointLabelTemplate.LoadContent() as FrameworkElement;
                lbl.DataContext = dp;
                if (Canvas.GetZIndex(lbl) == 0)
                {
                    Canvas.SetZIndex(lbl, 1);
                }
                if (pe != null)
                {
                    pe.Label = lbl;
                }
                else
                {
                    PlotElement.UpdateLabelPosition(element, lbl);
                }
                line = PlotElement.GetLabelLine(lbl);
            }
            if (pe == null)
            {
                return(null);
            }
            Size size = ds.GetSymbolSize(dp.PointIndex, _dataInfo, rc.Chart);

            if (!size.IsEmpty && (element != null))
            {
                element.Size = size;
            }
            if (!pe.Render(rc))
            {
                return(null);
            }
            if (lbl != null)
            {
                objects.Add(lbl);
                if (line != null)
                {
                    lbl.Loaded += (sender, e) =>
                    {
                        Canvas parent = (Canvas)lbl.Parent;
                        if (parent != null)
                        {
                            parent.Children.Add(line);
                        }
                    };
                }
            }
            if ((element.Center.X == 0.0) && (element.Center.Y == 0.0))
            {
                element.Center = rc.Current;
            }
            element.PlotRect = rc.Bounds;
            PlotElement.UpdateLabelPosition(element, pe.Label as FrameworkElement);
            if (element.DataContext == null)
            {
                element.DataContext = dp;
            }
            element.DataPoint = dp;
            AttachTooltip(ds, element);
            pe.SetShape(shapeStyle);
            ds.Children.Add((UIElement)pe);
            return((UIElement)pe);
        }