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() { 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); }
protected override void PrepareContainerForItemOverride(DependencyObject element, object dataItem) { PieChartItem item = element as PieChartItem; if (item != null) { item.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)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(); }