title: Stylizing graphs and tooltip of DataVisualization.Chart
body: <p>I'm creating a UserControl component of type DataVisualization.Chart. I'm building component based on the example of url: <a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=553" rel="nofollow noreferrer">http://www.dotnetcurry.com/ShowArticle.aspx?ID=553</a>. This chart will generate charts of the type chosen as either columns, bars, lines, Pie ... In the construction of the component, i'm inserting the Data Source than is passed through another View. So far so good. The chart for all types are generated normally.
  What I need to do now are 3 modifications in the component. But I can't find a way to resolve these modifications:</p>
  
  <ul>
  <li>When the user places the mouse over the value generated by the graph, the ToolTip appears the value of the object .. What I need is that the ToolTip Text appear as IndependentValuePath, which would be the name + value in the following format: "Name (value)";</li>
  <li>When a graph is generated, it inserts as a kind of label depending on the graph is the x axis or the y axis (as pictured). I need to remove it (Example in image);</li>
  <li>For graphs of type Column (and probably others yet to be confirmed), the outline of the rectangle must be the same color as the internal color. Besides being in the same color, each rectangle, which will change color according to a pre-defined range, which will be passed as the DataSource of the previous View .. What would be this: if the value is below 200, the color is red, if between 200 and 350, will be yellow ... and so on. I'll have about 5 limits;</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/PbzGN.png" alt="Example Modification"></p>
  
  <p>PS: the last <strong>THIS</strong> is the <strong>tooltip</strong>.</p>
  
  <p>Does anyone know how I can stylize these graphs and tooltip?</p>
  
  <p>Best regards,
  Gustavo</p>
  
  <p>Edit: Here's my UserControl Chart:</p>
  
  <pre><code>&lt;UserControl x:Class="Library.Core.GUI.WPF.Controls.ChartUCControl"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:ct="clr-namespace:Library.Core.GUI.WPF.Controls"
           xmlns:chart="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
           xmlns:sys="clr-namespace:System;assembly=mscorlib"
           mc:Ignorable="d" 
           x:Name="ChartUCControl1"&gt;
  &lt;UserControl.Resources&gt;
  
      &lt;Style TargetType="chart:ColumnDataPoint"&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="{x:Type chart:ColumnDataPoint}"&gt;
  
                          &lt;!--&lt;Border BorderThickness="0" Background="Red" ToolTip="asdfasdf"/&gt;--&gt;
                          &lt;Rectangle&gt;
                              &lt;Rectangle.Fill&gt;
                                  &lt;LinearGradientBrush&gt;
                                      &lt;GradientStop Color="Black" Offset="0"/&gt;
                                      &lt;GradientStop Color="White" Offset="1"/&gt;
                                  &lt;/LinearGradientBrush&gt;
                              &lt;/Rectangle.Fill&gt;
                          &lt;/Rectangle&gt;
  
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  
  &lt;/UserControl.Resources&gt;
  
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="*"/&gt;
          &lt;RowDefinition Height="auto"/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="*"/&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;ScrollViewer VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="auto"
                        HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" &gt;
              &lt;chart:Chart Name="chartView" Grid.Row="0" Title="{Binding TitleGraphic, Mode=TwoWay, ElementName=ChartUCControl1, UpdateSourceTrigger=PropertyChanged}" 
                         ScrollViewer.HorizontalScrollBarVisibility="Auto"
                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                         ScrollViewer.IsDeferredScrollingEnabled="True"
                         Width="{Binding WidthScrollViewer, Mode=TwoWay, ElementName=ChartUCControl1, UpdateSourceTrigger=PropertyChanged}"
                         MinWidth="{Binding MinWidthScrollViewer, Mode=TwoWay, ElementName=ChartUCControl1, UpdateSourceTrigger=PropertyChanged}"
                         HorizontalAlignment="{Binding HorizontalAlignmentGraphic, Mode=TwoWay, ElementName=ChartUCControl1, UpdateSourceTrigger=PropertyChanged}"  &gt;
  
                  &lt;chart:Chart.Series&gt;
                      &lt;chart:ColumnSeries &gt;
                          &lt;ToolTipService.ToolTip&gt;
                              &lt;ContentControl Content="asdçlfkj"/&gt;
                          &lt;/ToolTipService.ToolTip&gt;
                          &lt;chart:ColumnSeries.IndependentAxis&gt;
                              &lt;chart:CategoryAxis Orientation="X" Visibility="Visible" Height="0"/&gt;
                          &lt;/chart:ColumnSeries.IndependentAxis&gt;
                      &lt;/chart:ColumnSeries&gt;
                  &lt;/chart:Chart.Series&gt;
                  &lt;!--&lt;ToolTipService.ToolTip&gt;
                      &lt;ContentControl Content="{TemplateBinding IndependentValue}" /&gt;
                  &lt;/ToolTipService.ToolTip&gt;--&gt;
                  &lt;!--PreviewMouseMove="chartView_PreviewMouseMove"--&gt;
  
                  &lt;!--&lt;chart:Chart.Series&gt;
                      &lt;chart:ColumnSeries&gt;
                          &lt;chart:DataPointSeries.DataPointStyle&gt;
                              &lt;Style TargetType="chart:ColumnDataPoint"&gt;
                                  &lt;Setter Property="Template"&gt;
                                      &lt;Setter.Value&gt;
                                          &lt;ControlTemplate TargetType="{x:Type chart:ColumnDataPoint}"&gt;
                                              &lt;Border BorderBrush="Black" &gt;
                                                  &lt;ToolTipService.ToolTip&gt;
                                                  &lt;ContentControl Content="{Binding ToolTip}"/&gt;
                                              &lt;/ToolTipService.ToolTip&gt;
                                                  &lt;Border BorderBrush="Black" BorderThickness="1"/&gt;
                                                  &lt;ToolTipService.ToolTip&gt;
                                                      &lt;ContentControl Content="asçldfkj"/&gt;
                                                  &lt;/ToolTipService.ToolTip&gt;
                                              &lt;/Border&gt;
                                              &lt;ToolTip Content="çlkjasf"/&gt;
  
                                              &lt;Rectangle&gt;
                                                  &lt;Rectangle.Fill&gt;
                                                      &lt;SolidColorBrush Color="Blue"/&gt;
                                                  &lt;/Rectangle.Fill&gt;
                                              &lt;/Rectangle&gt;
  
                                          &lt;/ControlTemplate&gt;
                                      &lt;/Setter.Value&gt;
                                  &lt;/Setter&gt;
                              &lt;/Style&gt;
                          &lt;/chart:DataPointSeries.DataPointStyle&gt;
                      &lt;/chart:ColumnSeries&gt;
                  &lt;/chart:Chart.Series&gt;--&gt;
  
                  &lt;!--&lt;Style TargetType="{x:Type chart:ColumnDataPoint}"&gt;
                              &lt;Setter Property="Background" Value="Orange" /&gt;
                              &lt;Setter Property="BorderBrush" Value="Black" /&gt;
                              &lt;Setter Property="BorderThickness" Value="1" /&gt;
                              &lt;Setter Property="IsTabStop" Value="False" /&gt;
                              &lt;Setter Property="Template"&gt;
                                  &lt;Setter.Value&gt;
                                      &lt;ControlTemplate TargetType="{x:Type chart:ColumnSeries}"&gt;
                                          &lt;Border BorderBrush="Azure" BorderThickness="10" Opacity="10" x:Name="Root"&gt;
                                              &lt;Grid Background="Black"&gt;
                                                  &lt;Rectangle&gt;
                                                      &lt;Rectangle.Fill&gt;
                                                          &lt;LinearGradientBrush&gt;
                                                              &lt;GradientStop Color="Black" Offset="0" /&gt;
                                                              &lt;GradientStop Color="Black" Offset="1" /&gt;
                                                          &lt;/LinearGradientBrush&gt;
                                                      &lt;/Rectangle.Fill&gt;
                                                  &lt;/Rectangle&gt;
                                                  &lt;Border BorderBrush="#ccffffff" BorderThickness="1"&gt;
                                                      &lt;Border BorderBrush="#77ffffff" BorderThickness="1" /&gt;
                                                  &lt;/Border&gt;
                                                  &lt;Rectangle x:Name="SelectionHighlight" Fill="Red" Opacity="0" /&gt;
                                                  &lt;Rectangle x:Name="MouseOverHighlight" Fill="White" Opacity="0" /&gt;
                                              &lt;/Grid&gt;
                                              &lt;ToolTipService.ToolTip&gt;
                                                  &lt;ContentControl Content="as" /&gt;
                                              &lt;/ToolTipService.ToolTip&gt;
                                          &lt;/Border&gt;
                                      &lt;/ControlTemplate&gt;
                                  &lt;/Setter.Value&gt;
                              &lt;/Setter&gt;
                          &lt;/Style&gt;--&gt;
  
                  &lt;!--&lt;ToolTipService.ToolTip&gt;
                                                      &lt;ContentControl Content="{Binding Identificacao}"/&gt;
                                                  &lt;/ToolTipService.ToolTip&gt;--&gt;
                  &lt;!--&lt;Grid&gt;
                                                  &lt;Rectangle&gt;
                                                      &lt;Rectangle.Fill&gt;
                                                          &lt;LinearGradientBrush&gt;
                                                              &lt;GradientStop Color="Blue" Offset="0"/&gt;
                                                              &lt;GradientStop Color="Black" Offset="1"/&gt;
                                                          &lt;/LinearGradientBrush&gt;
                                                      &lt;/Rectangle.Fill&gt;
                                                  &lt;/Rectangle&gt;
                                              &lt;/Grid&gt;--&gt;
  
                  &lt;chart:Chart.Axes&gt;
                      &lt;chart:LinearAxis Orientation="X" Interval="{Binding IntervalAxis, ElementName=ChartUCControl1, Mode=TwoWay}" 
                                      MouseEnter="chartView_PreviewMouseMove"
                                      Maximum="{Binding MaximumAxis, ElementName=ChartUCControl1, Mode=TwoWay}"/&gt;
                      &lt;!-- This section configures labels of X Orientation --&gt;
                      &lt;chart:CategoryAxis Orientation="X" Visibility="Hidden"/&gt;
                  &lt;/chart:Chart.Axes&gt;
  
                  &lt;chart:Chart.LegendStyle&gt;
                      &lt;Style TargetType="Control"&gt;
                          &lt;Setter Property="Width" Value="0"/&gt;
                          &lt;Setter Property="Height" Value="0"/&gt;
                      &lt;/Style&gt;
                  &lt;/chart:Chart.LegendStyle&gt;
  
                  &lt;chart:Chart.PlotAreaStyle&gt;
                      &lt;Style TargetType="Grid"&gt;
                          &lt;Setter Property="Background" Value="Transparent"/&gt;
                          &lt;!--&lt;Setter Property="ToolTip" Value="{x:Null}"/&gt;--&gt;
                      &lt;/Style&gt;
                  &lt;/chart:Chart.PlotAreaStyle&gt;
              &lt;/chart:Chart&gt;
          &lt;/ScrollViewer&gt;
      &lt;/Grid&gt;
  &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p><strong>IN case</strong> of need to look my code-behind:</p>
  
  <pre><code>namespace Library.Core.GUI.WPF.Controls
  {
      public partial class ChartUCControl : UserControl, INotifyPropertyChanged
      {
          #region Constructors
  
          public ChartUCControl()
          {
              InitializeComponent();
          }
  
          #endregion
  
          #region ChartType Property
  
          public static ChartTypes GetChartType(DependencyObject d)
          {
              return (ChartTypes)d.GetValue(ChartTypeProperty);
          }
  
          public static void SetChartType(DependencyObject d, ChartTypes value)
          {
              d.SetValue(ChartTypeProperty, value);
          }
  
          public static readonly DependencyProperty ChartTypeProperty =
              DependencyProperty.RegisterAttached(
                  "ChartType",
                  typeof(ChartTypes),
                  typeof(ChartUCControl),
                  new FrameworkPropertyMetadata(ChartTypeChangedCallback)
                  );
  
          private static void ChartTypeChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
          {
              Chart instance = (d as Chart);
              if (instance.IsNull())
                  return;
  
              SetChartType(d, (ChartTypes)e.NewValue);
  
              ChartUCControl instance2 = (d as ChartUCControl);
          }
  
          private ChartTypes chartType;
          public ChartTypes ChartType
          {
              get { return chartType; }
              set { chartType = value; }
          }
  
          #endregion
  
          #region ChartAreaSelected Property
  
          public static readonly DependencyProperty ChartAreaProperty =
              DependencyProperty.RegisterAttached(
                  "ChartArea",
                  typeof(Boolean),
                  typeof(ChartUCControl),
                          new FrameworkPropertyMetadata(ChartAreaChangedCallback));
  
          private static void ChartAreaChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
          {
              ChartUCControl instance = (d as ChartUCControl);
  
              if (instance.IsNull())
                  return;
  
              instance.ChartArea = (Boolean)e.NewValue;
          }
  
          private Boolean chartArea;
          public Boolean ChartArea
          {
              get { return chartArea; }
              set
              {
                  chartArea = value;
                  if (value)
                  {
                      cmbChart.SelectedItem = ChartTypes.Area;
                      DoRenderizeGraphic();
                  }
              }
          }
  
          #endregion
  
          #region ChartBarSelected Property
  
          public static readonly DependencyProperty ChartBarProperty =
              DependencyProperty.RegisterAttached(
                  "ChartBar",
                  typeof(Boolean),
                  typeof(ChartUCControl),
                  new FrameworkPropertyMetadata(ChartBarChangedCallback));
  
          private static void ChartBarChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
          {
              ChartUCControl instance = (d as ChartUCControl);
  
              if (instance.IsNull())
                  return;
  
              instance.ChartBar = (Boolean)e.NewValue;
          }
  
          private Boolean chartBar;
          public Boolean ChartBar
          {
              get { return chartBar; }
              set
              {
                  chartBar = value;
                  if (value)
                  {
                      cmbChart.SelectedItem = ChartTypes.Bar;
                      DoRenderizeGraphic();
                  }
              }
          }
  
          #endregion
  
          #region ChartColumnSelected Property
  
          public static readonly DependencyProperty ChartColumnProperty =
              DependencyProperty.RegisterAttached(
                  "ChartColumn",
                  typeof(Boolean),
                  typeof(ChartUCControl),
                  new FrameworkPropertyMetadata(ChartColumnChangedCallback)
                  );
  
          private static void ChartColumnChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
          {
              ChartUCControl instance = (d as ChartUCControl);
              if (instance.IsNull())
                  return;
  
              instance.ChartColumn = (Boolean)e.NewValue;
          }
  
          private Boolean chartColumn;
          public Boolean ChartColumn
          {
              get { return chartColumn; }
              set
              {
                  chartColumn = value;
  
                  if (value)
                  {
                      cmbChart.SelectedItem = ChartTypes.Columns;
                      DoRenderizeGraphic();
                  }
              }
          }
  
          #endregion
          #region ChartLinesSelected Property
  
          public static readonly DependencyProperty ChartLinesProperty =
              DependencyProperty.RegisterAttached(
                  "ChartLines",
                  typeof(Boolean),
                  typeof(ChartUCControl),
                  new FrameworkPropertyMetadata(ChartLinesChangedCallback));
  
          private static void ChartLinesChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
          {
              ChartUCControl instance = (d as ChartUCControl);
              if (instance.IsNull())
                  return;
  
              instance.ChartLines = (Boolean)e.NewValue;
          }
  
          private Boolean chartLines;
          public Boolean ChartLines
          {
              get { return chartLines; }
              set
              {
                  chartLines = value;
                  if (value)
                  {
                      cmbChart.SelectedItem = ChartTypes.Lines;
                      DoRenderizeGraphic();
                  }
              }
          }
  
          #endregion
  
          #region FieldForIndependentValue Property
  
          /// &lt;summary&gt;
          /// String containing list of the only characters allowed, others will be filtered
          /// &lt;/summary&gt;
          public String FieldForIndependentValue
          {
              get { return (String)GetValue(FieldForIndependentValueProperty); }
              set { SetValue(FieldForIndependentValueProperty, value); }
          }
  
          public static readonly DependencyProperty FieldForIndependentValueProperty =
              DependencyProperty.Register("FieldForIndependentValue", typeof(String), typeof(ChartUCControl));
  
          #endregion
  
          #region FieldForDependentValue Property
  
          /// &lt;summary&gt;
          /// String containing list of the only characters allowed, others will be filtered
          /// &lt;/summary&gt;
          public String FieldForDependentValue
          {
              get { return (String)GetValue(FieldForDependentValueProperty); }
              set { SetValue(FieldForDependentValueProperty, value); }
          }
  
          public static readonly DependencyProperty FieldForDependentValueProperty =
              DependencyProperty.Register("FieldForDependentValue", typeof(String), typeof(ChartUCControl));
  
          #endregion
  
          #region TitleGraphic Property
  
          public String TitleGraphic
          {
              get { return (String)base.GetValue(TitleGraphicProperty); }
              set { base.SetValue(TitleGraphicProperty, value); }
          }
  
          public static readonly DependencyProperty TitleGraphicProperty =
              DependencyProperty.RegisterAttached(
                  "TitleGraphic",
                  typeof(String),
                  typeof(ChartUCControl),
                  new FrameworkPropertyMetadata(null)
                  );
  
          #endregion
  
          #region MinWidthScrollViewer Property
  
          public String MinWidthScrollViewer
          {
              get { return (String)base.GetValue(MinWidthScrollViewerProperty); }
              set { base.SetValue(MinWidthScrollViewerProperty, value); }
          }
  
          public static readonly DependencyProperty MinWidthScrollViewerProperty =
              DependencyProperty.RegisterAttached(
              "MinWidthScrollViewer",
              typeof(String),
              typeof(ChartUCControl),
              new FrameworkPropertyMetadata(null));
  
          #endregion
  
          #region Width ScrollViewer Property
  
          public String WidthScrollViewer
          {
              get { return (String)base.GetValue(WidthScrollViewerProperty); }
              set { base.SetValue(WidthScrollViewerProperty, value); }
          }
  
          public static readonly DependencyProperty WidthScrollViewerProperty =
              DependencyProperty.RegisterAttached(
                  "WidthScrollViewer",
                  typeof(String),
                  typeof(ChartUCControl),
                  new FrameworkPropertyMetadata(null)
                  );
  
          #endregion
  
          #region ItemsSource Property
  
          public IEnumerable ItemsSource
          {
              get { return (IEnumerable)base.GetValue(ItemsSourceProperty); }
              set { base.SetValue(ItemsSourceProperty, value); }
          }
  
          public static readonly DependencyProperty ItemsSourceProperty =
              DependencyProperty.RegisterAttached(
              "ItemsSource",
              typeof(IEnumerable),
              typeof(ChartUCControl),
              new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  
          #endregion
  
          #region Methods
  
          private void ImageButton_Click_1(object sender, RoutedEventArgs e)
          {
              DoRenderizeGraphic();
          }
  
          public void DoRenderizeGraphic()
          {
              while (this.chartView.Series.Count() - 1 &gt;= 0)
                  this.chartView.Series.Remove(this.chartView.Series[0]);
  
              DataPointSeries objChar = null;
  
              if (!cmbChart.SelectedItem.IsNull())
                  switch ((ChartTypes)cmbChart.SelectedValue)
                  {
                      case ChartTypes.Bar:
                          this.chartView.Series.Add(new BarSeries());
                          objChar = this.chartView.Series[0] as BarSeries;
                          break;
  
                      case ChartTypes.Columns:
                          this.chartView.Series.Add(new ColumnSeries());
                          objChar = this.chartView.Series[0] as ColumnSeries;
  
                          break;
  
                      case ChartTypes.Pie:
                          this.chartView.Series.Add(new PieSeries());
                          objChar = this.chartView.Series[0] as PieSeries;
                          break;
  
                      case ChartTypes.Lines:
                          this.chartView.Series.Add(new LineSeries());
                          objChar = this.chartView.Series[0] as LineSeries;
                          break;
  
                      case ChartTypes.Area:
                          this.chartView.Series.Add(new AreaSeries());
                          objChar = this.chartView.Series[0] as AreaSeries;
                          break;
  
                      default:
                          break;
                  }
  
              if (!objChar.IsNull())
              {
                  objChar.IsSelectionEnabled = true;
  
                  objChar.DependentValuePath = FieldForDependentValue;
                  objChar.IndependentValuePath = FieldForIndependentValue;
                  objChar.ItemsSource = ItemsSource;
  
  
                  if (this.chartView.Axes.Count &gt; 0
                     &amp;&amp; (!this.chartView.ActualAxes[0].IsNull() || !this.chartView.ActualAxes[0].DependentAxes.IsNull()))
                      foreach (var item in this.chartView.ActualAxes[0].DependentAxes)
                      {
                          this.chartView.ActualAxes[0].DependentAxes.Remove(item);
                      }
  
              }
          }
  
          #endregion
  
          #region Properties
  
          private String[] chartTypesList;
          public String[] ChartTypesList
          {
              get { return chartTypesList; }
              set
              {
                  chartTypesList = value;
                  OnPropertyChanged("ChartTypesList");
              }
          }
  
          private String chartTypeSelectedValue;
          public String ChartTypeSelectedValue
          {
              get { return chartTypeSelectedValue; }
              set
              {
                  chartTypeSelectedValue = value;
                  OnPropertyChanged("ChartTypeSelectedValue");
              }
          }
  
          #endregion
  
          #region INotifyPropertyChanged event and method
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          private void OnPropertyChanged(String info)
          {
              if (!PropertyChanged.IsNull())
                  PropertyChanged(this, new PropertyChangedEventArgs(info));
          }
  
          #endregion
  
          #region Preview Mouse events
  
          private void chartView_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
          {
              var t = ((e.OriginalSource) as FrameworkElement).DataContext;
  
              if (!t.IsNull() &amp;&amp; e.OriginalSource.GetType().Equals(typeof(System.Windows.Shapes.Rectangle)))
              {
                  Object a = null;
  
                  foreach (PropertyInfo item in ((e.OriginalSource) as FrameworkElement).DataContext.GetType().GetProperties())
                  {
                      a = item.GetValue(((e.OriginalSource) as FrameworkElement).DataContext, null);
                      break;
                  }
  
                  if (a == null)
                      a = "";
                  ((FrameworkElement)(e.OriginalSource)).ToolTip = a;
              }
          }
  
          #endregion
  
          #region ReflectionReturn Seekers
  
          public List&lt;Control&gt; FindAllControls(DependencyObject parent)
          {
              var list = new List&lt;Control&gt;() { };
  
              for (int i = 0; i &lt; VisualTreeHelper.GetChildrenCount(parent); i++)
              {
                  var child = VisualTreeHelper.GetChild(parent, i);
                  if (child is Control)
                  {
                      list.Add(child as Control);
  
                  }
                  list.AddRange(FindAllControls(child));
              }
              return list;
          }
  
          public IEnumerable&lt;FieldInfo&gt; GetAllFields(Type t)
          {
              if (t.IsNull())
                  return Enumerable.Empty&lt;FieldInfo&gt;();
  
              BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
  
              return t.GetFields(flags).Union(GetAllFields(t.BaseType));
          }
  
          #endregion
  
      }
      #region Enum
  
      public enum ChartTypes
      {
          Bar,
          Columns,
          Pie,
          Lines,
          Area
      }
  
      #endregion
  }
  </code></pre>