/// <summary> /// Creates the LegendItem Control if conditions are right. /// </summary> private void CreateLegendItemDataPoint() { DataPoint dataPoint = CreateDataPoint(); if (null != PlotArea) { // Bounce into the visual tree to get default Style applied PlotArea.Children.Add(dataPoint); PlotArea.Children.Remove(dataPoint); } dataPoint.SetBinding(DataPoint.StyleProperty, new Binding(ActualDataPointStyleName) { Source = this }); // Start DataContext null to avoid Binding warnings in the output window LegendItem.DataContext = null; #if !SILVERLIGHT if (null == LegendItem.Parent) { #endif LegendItem.Loaded += delegate { // Wait for Loaded to set the DataPoint LegendItem.DataContext = dataPoint; } ; #if !SILVERLIGHT } else { LegendItem.DataContext = dataPoint; } #endif }
/// <summary> /// Sets the style of the data point to the single style used for all /// data points. /// </summary> /// <param name="dataPoint">The data point to apply the style to. /// </param> /// <param name="dataContext">The object associated with the data point. /// </param> protected override void PrepareDataPoint(DataPoint dataPoint, object dataContext) { dataPoint.SetBinding(DataPoint.StyleProperty, new Binding(ActualDataPointStyleName) { Source = this }); base.PrepareDataPoint(dataPoint, dataContext); }
/// <summary> /// Prepares a data point by extracting binding it to a data context /// object. /// </summary> /// <param name="dataPoint">A data point.</param> /// <param name="dataContext">A data context object.</param> protected virtual void PrepareDataPoint(DataPoint dataPoint, object dataContext) { // Create a Control with DataContext set to the data source dataPoint.DataContext = dataContext; // Set bindings for IndependentValue/DependentValue if (IndependentValueBinding != null) { dataPoint.SetBinding(DataPoint.IndependentValueProperty, IndependentValueBinding); } if (DependentValueBinding == null) { dataPoint.SetBinding(DataPoint.DependentValueProperty, new Binding()); } else { dataPoint.SetBinding(DataPoint.DependentValueProperty, DependentValueBinding); } }
/// <summary> /// Creates a legend item from a data point. /// </summary> /// <param name="dataPoint">The data point to use to create the legend item.</param> /// <param name="index">The 1-based index of the Control.</param> /// <returns>The series host legend item.</returns> protected virtual LegendItem CreatePieLegendItem(DataPoint dataPoint, int index) { LegendItem legendItem = CreateLegendItem(this); // Set the Content of the LegendItem legendItem.Content = dataPoint.IndependentValue ?? index; // Create a representative DataPoint for access to styled properties DataPoint legendDataPoint = CreateDataPoint(); legendDataPoint.DataContext = dataPoint.DataContext; if (null != PlotArea) { // Bounce into the visual tree to get default Style applied PlotArea.Children.Add(legendDataPoint); PlotArea.Children.Remove(legendDataPoint); } legendDataPoint.SetBinding(DataPoint.StyleProperty, new Binding(PieDataPoint.ActualDataPointStyleName) { Source = dataPoint }); legendItem.DataContext = legendDataPoint; return(legendItem); }