示例#1
0
        private double GetPercentage(PieChartItem item)
        {
            double sum   = EnumerateItems().Sum(i => i.Value);
            double value = item.Value;

            return((value / sum) * 100);
        }
示例#2
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            PieChartItem item = new PieChartItem();

            if (!String.IsNullOrEmpty(ValuePath))
            {
                item.SetBinding(PieChartItem.ValueProperty, new Binding()
                {
                    Path = new PropertyPath(ValuePath)
                });
            }

            if (!String.IsNullOrEmpty(ForegroundPath))
            {
                item.SetBinding(PieChartItem.ForegroundProperty, new Binding()
                {
                    Path = new PropertyPath(ForegroundPath)
                });
            }

            if (!String.IsNullOrEmpty(LabelPath))
            {
                item.SetBinding(PieChartItem.LabelProperty, new Binding()
                {
                    Path = new PropertyPath(LabelPath)
                });
            }

            return(item);
        }
示例#3
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object dataItem)
        {
            PieChartItem item = element as PieChartItem;

            if (item != null)
            {
                item.LabelTemplate = ItemTemplate;
            }
        }
示例#4
0
        private IEnumerable <PieChartItem> EnumerateItems()
        {
            for (int i = 0; i < Items.Count; i++)
            {
                PieChartItem item = Items[i] as PieChartItem;
                if (item == null)
                {
                    item = (PieChartItem)ContainerFromIndex(i);
                }

                if (item != null)
                {
                    yield return(item);
                }
            }
        }
示例#5
0
        private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PieChartItem item = (PieChartItem)d;

            if (item.Label != null && item.LabelTemplate != null)
            {
                throw new NotSupportedException("PieChartItem, set Label or LabelTemplate, not both.");
            }

            if (item.Label != null || item.LabelTemplate != null)
            {
                item.labelPanel.Visibility = Visibility.Visible;
            }
            else
            {
                item.labelPanel.Visibility = Visibility.Collapsed;
            }

            if (item.Label != null)
            {
                item.label.Content = item.Label;
            }
        }
示例#6
0
        private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PieChartItem pc = (PieChartItem)d;

            pc.NotifyUpdate();
        }