示例#1
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            PieChartItem item = new PieChartItem();

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

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

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

            if (!String.IsNullOrEmpty(TooltipPath))
            {
                item.SetBinding(PieChartItem.ToolTipProperty, new Binding(TooltipPath));
            }

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

            return((value / sum) * 100);
        }
示例#3
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            PieChartItem chartItem = element as PieChartItem;

            if (chartItem != null)
            {
                chartItem.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)ItemContainerGenerator.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();
        }
        private double GetPercentage(PieChartItem item)
        {
            double sum = EnumerateItems().Sum(i => i.Value);
            double value = item.Value;

            return (value / sum) * 100;
        }
        protected override DependencyObject GetContainerForItemOverride()
        {
            PieChartItem item = new PieChartItem();

            if (!String.IsNullOrEmpty(ValuePath))
                item.SetBinding(PieChartItem.ValueProperty, new Binding(ValuePath));

            if (!String.IsNullOrEmpty(ForegroundPath))
                item.SetBinding(PieChartItem.ForegroundProperty, new Binding(ForegroundPath));

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

            if (!String.IsNullOrEmpty(TooltipPath))
                item.SetBinding(PieChartItem.ToolTipProperty, new Binding(TooltipPath));

            return item;
        }