/// <summary>
        /// Signals to the Chart that a Series no longer needs to use the axis
        /// within this series host.
        /// </summary>
        /// <param name="series">The Series object that no longer needs to use
        /// the axis.</param>
        /// <param name="axis">The axis that the Series no longer needs to use.
        /// </param>
        void ISeriesHost.UnregisterWithAxis(Series series, IAxis axis)
        {
            if (series == null)
            {
                throw new ArgumentNullException("series");
            }
            if (axis == null)
            {
                throw new ArgumentNullException("axis");
            }
            if (!ActualAxes.Contains(axis))
            {
                throw new InvalidOperationException(Properties.Resources.Chart_UnregisterWithSeries_OneAxisCannotBeUsedByMultipleCharts);
            }

            axis.Unregister(series);
            // If axis is no longer used and is not in external axes collection
            if (!axis.IsUsed && !Axes.Contains(axis))
            {
                InternalActualAxes.Remove(axis);
            }
        }
        /// <summary>
        /// Builds the visual tree for the Chart control when a new template
        /// is applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            // Call base implementation
            base.OnApplyTemplate();

            // Unhook events from former template parts
            if (null != ChartArea)
            {
                ChartArea.Children.Clear();
            }

            if (null != PlotArea)
            {
                PlotArea.Children.Clear();
            }

            if (null != SeriesContainer)
            {
                SeriesContainer.Children.Clear();
                _seriesCollectionSeriesContainerAdapter.TargetList = null;
            }

            if (null != GridLinesContainer)
            {
                GridLinesContainer.Children.Clear();
                _gridLinesContainerChildrenChartAreaAdapter.TargetList = null;
            }

            if (null != Legend)
            {
                Legend.LegendItems.Clear();
                _legendChildrenLegendAdapter.TargetList = null;
            }

            // Access new template parts
            ChartArea          = GetTemplateChild(ChartAreaName) as Grid;
            PlotArea           = GetTemplateChild(PlotAreaName) as Grid;
            SeriesContainer    = GetTemplateChild(SeriesContainerName) as Panel;
            GridLinesContainer = GetTemplateChild(GridLinesContainerName) as Panel;
            Legend             = GetTemplateChild(LegendName) as Legend;

            StyleDispenser.Reset();

            if (Legend != null)
            {
                _legendChildrenLegendAdapter.TargetList = Legend.LegendItems;
                _legendChildrenLegendAdapter.Populate();
            }

            if (SeriesContainer != null)
            {
                _seriesCollectionSeriesContainerAdapter.TargetList = SeriesContainer.Children;
                _seriesCollectionSeriesContainerAdapter.Populate();
            }

            if (GridLinesContainer != null)
            {
                _gridLinesContainerChildrenChartAreaAdapter.TargetList = GridLinesContainer.Children;
                _gridLinesContainerChildrenChartAreaAdapter.Populate();
            }

            if (ChartArea != null)
            {
                foreach (Axis axis in ActualAxes.OfType <Axis>())
                {
                    ChartArea.Children.Add(axis);
                }

                RebuildChartArea();
            }
        }