/// <summary> /// Initializes a new instance of the ISeriesHost class. /// </summary> public Chart() { DefaultStyleKey = typeof(Chart); // Create the backing collection for Series ObservableCollection <Series> series = new NoResetObservableCollection <Series>(); series.CollectionChanged += new NotifyCollectionChangedEventHandler(OnSeriesCollectionChanged); _series = series; _seriesCollectionSeriesContainerAdapter.Collection = series; // Create the backing collection for Axes ObservableCollection <IAxis> axes = new NoResetObservableCollection <IAxis>(); axes.CollectionChanged += new NotifyCollectionChangedEventHandler(OnAxesCollectionChanged); _axes = axes; ObservableCollection <IAxis> actualAxes = new ObservableCollection <IAxis>(); actualAxes.CollectionChanged += new NotifyCollectionChangedEventHandler(ActualAxesCollectionChanged); this.InternalActualAxes = actualAxes; this.ActualAxes = new ReadOnlyCollection <IAxis>(InternalActualAxes); _gridLinesContainerChildrenChartAreaAdapter.Collection = _gridLinesContainerChildren; // Create collection for LegendItems AggregatedObservableCollection <UIElement> chartLegendItems = new AggregatedObservableCollection <UIElement>(); _legendChildrenLegendAdapter.Collection = chartLegendItems; LegendItems = chartLegendItems; ISeriesHost host = this as ISeriesHost; host.GlobalSeriesIndexesInvalidated += OnGlobalSeriesIndexesInvalidated; // Create style dispenser StyleDispenser = new StyleDispenser(); }
/// <summary> /// Initializes a new instance of the ISeriesHost class. /// </summary> public Chart() { DefaultStyleKey = typeof(Chart); // Create the backing collection for Series ObservableCollection<Series> series = new NoResetObservableCollection<Series>(); series.CollectionChanged += new NotifyCollectionChangedEventHandler(OnSeriesCollectionChanged); _series = series; _seriesCollectionSeriesContainerAdapter.Collection = series; // Create the backing collection for Axes ObservableCollection<IAxis> axes = new NoResetObservableCollection<IAxis>(); axes.CollectionChanged += new NotifyCollectionChangedEventHandler(OnAxesCollectionChanged); _axes = axes; ObservableCollection<IAxis> actualAxes = new ObservableCollection<IAxis>(); actualAxes.CollectionChanged += new NotifyCollectionChangedEventHandler(ActualAxesCollectionChanged); this.InternalActualAxes = actualAxes; this.ActualAxes = new ReadOnlyCollection<IAxis>(InternalActualAxes); _gridLinesContainerChildrenChartAreaAdapter.Collection = _gridLinesContainerChildren; // Create collection for LegendItems AggregatedObservableCollection<UIElement> chartLegendItems = new AggregatedObservableCollection<UIElement>(); _legendChildrenLegendAdapter.Collection = chartLegendItems; LegendItems = chartLegendItems; ISeriesHost host = this as ISeriesHost; host.GlobalSeriesIndexesInvalidated += OnGlobalSeriesIndexesInvalidated; // Create style dispenser StyleDispenser = new StyleDispenser(); }
/// <summary> /// Returns a style matching the specified target type from a pool of /// available styles. Once all styles are used the available pool of /// styles is reset. /// </summary> /// <param name="targetType">The target type of the requested style. /// </param> /// <param name="inherit">Whether to return ancestors of the /// target type.</param> /// <returns>The next applicable style in the Styles collection. /// </returns> public Style NextStyle(Type targetType, bool inherit) { return(StyleDispenser.NextStyle(targetType, inherit)); }
/// <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(); } }