Example #1
0
        /// <summary>
        /// Adds the labels to each of its PieDataPoints.
        /// </summary>
        protected override void OnAfterUpdateDataPoints()
        {
            LabeledPieChart chart = this.SeriesHost as LabeledPieChart;

            if (chart != null)
            {
                Panel labelArea = TreeHelper.FindDescendent(chart, "LabelArea_PART") as Panel;
                if (labelArea != null && this.ItemsSource != null)
                {
                    foreach (object dataItem in this.ItemsSource)
                    {
                        PieDataPoint pieDataPoint = this.GetDataPoint(dataItem) as PieDataPoint;
                        if (pieDataPoint != null)
                        {
                            this.AddLabelPieDataPoint(pieDataPoint, labelArea);
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new PieChartLabel control and adds it to the "LabelArea_PART" canvas.
        /// </summary>
        /// <param name="pieDataPoint">PieDataPoint that corresponds to PieChartLabel.</param>
        /// <param name="labelStyle">The style to be applied to the PieChartLabel.</param>
        /// <param name="labelArea">The canvas where PieChartLabel will be added.</param>
        private static void AddLabel(PieDataPoint pieDataPoint, Panel labelArea)
        {
            PieChartLabel label = new PieChartLabel();

            Style           pieChartLabelStyle;
            DataTemplate    pieChartLabelItemTemplate;
            LabeledPieChart chart = TreeHelper.FindAncestor <LabeledPieChart>(pieDataPoint);

            if (chart != null)
            {
                pieChartLabelStyle = chart.PieChartLabelStyle;
                if (pieChartLabelStyle != null)
                {
                    label.Style = pieChartLabelStyle;
                }
                pieChartLabelItemTemplate = chart.PieChartLabelItemTemplate;
                if (pieChartLabelItemTemplate != null)
                {
                    label.ContentTemplate = pieChartLabelItemTemplate;
                }
            }

            Binding contentBinding = new Binding("DataContext")
            {
                Source = pieDataPoint
            };

            label.SetBinding(ContentControl.ContentProperty, contentBinding);

            Binding dataContextBinding = new Binding("DataContext")
            {
                Source = pieDataPoint
            };

            label.SetBinding(ContentControl.DataContextProperty, contentBinding);

            Binding formattedRatioBinding = new Binding("FormattedRatio")
            {
                Source = pieDataPoint
            };

            label.SetBinding(PieChartLabel.FormattedRatioProperty, formattedRatioBinding);

            Binding visibilityBinding = new Binding("Ratio")
            {
                Source = pieDataPoint, Converter = new DoubleToVisibilityConverter()
            };

            label.SetBinding(PieChartLabel.VisibilityProperty, visibilityBinding);

            Binding geometryBinding = new Binding("Geometry")
            {
                Source = pieDataPoint
            };

            label.SetBinding(PieChartLabel.GeometryProperty, geometryBinding);

            Binding displayModeBinding = new Binding("LabelDisplayMode")
            {
                Source = chart
            };

            label.SetBinding(PieChartLabel.DisplayModeProperty, displayModeBinding);

            labelArea.Children.Add(label);

            pieDataPoint.Loaded += delegate
            {
                if (label.Parent == null)
                {
                    labelArea.Children.Add(label);
                }
            };

            pieDataPoint.LayoutUpdated += delegate
            {
                if (!pieDataPoint.IsInTree())
                {
                    labelArea.Children.Remove(label);
                }
            };

            //pieDataPoint.Unloaded += delegate
            //{
            //    labelArea.Children.Remove(label);
            //};
        }