private void OnChartPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "Description")
     {
         ViewportElement2D chart = sender as ViewportElement2D;
         if (chart != null && cachedLegendItems.ContainsKey(chart))
         {
             // todo dirty, but quick to code.
             PopulateLegend();
         }
     }
 }
        private void graph_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Description")
            {
                ViewportElement2D graph         = (ViewportElement2D)sender;
                LegendItem        oldLegendItem = cachedLegendItems[graph];
                int index = stackPanel.Children.IndexOf(oldLegendItem);
                stackPanel.Children.RemoveAt(index);

                LegendItem newLegendItem = graph.Description.LegendItem;
                cachedLegendItems[graph] = newLegendItem;
                stackPanel.Children.Insert(index, newLegendItem);
            }
        }