コード例 #1
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 void AddLabelPieDataPoint(PieDataPoint pieDataPoint, Canvas labelArea)
        {
            PieChartLabel label = new PieChartLabel();

            label.Style           = this.PieChartLabelStyle;
            label.ContentTemplate = this.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 = this
            };

            label.SetBinding(PieChartLabel.DisplayModeProperty, displayModeBinding);

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

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