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); }
private double GetPercentage(PieChartItem item) { double sum = EnumerateItems().Sum(i => i.Value); double value = item.Value; return((value / sum) * 100); }
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { PieChartItem chartItem = element as PieChartItem; if (chartItem != null) { chartItem.LabelTemplate = ItemTemplate; } }
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); } } }
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; } }
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; }