// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Windows.Controls.DataVisualization.Charting.Primitives;
using System.Windows.Markup;
namespace System.Windows.Controls.DataVisualization.Charting
{
///
/// Represents a control that displays a Chart.
///
/// Preview
[TemplatePart(Name = Chart.ChartAreaName, Type = typeof(EdgePanel))]
[TemplatePart(Name = Chart.LegendName, Type = typeof(Legend))]
[StyleTypedProperty(Property = "TitleStyle", StyleTargetType = typeof(Title))]
[StyleTypedProperty(Property = "LegendStyle", StyleTargetType = typeof(Legend))]
[StyleTypedProperty(Property = "ChartAreaStyle", StyleTargetType = typeof(EdgePanel))]
[StyleTypedProperty(Property = "PlotAreaStyle", StyleTargetType = typeof(Grid))]
[ContentProperty("Series")]
public partial class Chart : Control, ISeriesHost
{
///
/// Specifies the name of the ChartArea TemplatePart.
///
private const string ChartAreaName = "ChartArea";
///
/// Specifies the name of the legend TemplatePart.
///
private const string LegendName = "Legend";
///
/// Gets or sets the chart area children collection.
///
private AggregatedObservableCollection ChartAreaChildren { get; set; }
///
/// An adapter that synchronizes changes to the ChartAreaChildren
/// property to the ChartArea panel's children collection.
///
private ObservableCollectionListAdapter _chartAreaChildrenListAdapter = new ObservableCollectionListAdapter();
///
/// Gets or sets a collection of Axes in the Chart.
///
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Setter is public to work around a limitation with the XAML editing tools.")]
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "value", Justification = "Setter is public to work around a limitation with the XAML editing tools.")]
public Collection Axes
{
get
{
return _axes;
}
set
{
throw new NotSupportedException(Properties.Resources.Chart_Axes_SetterNotSupported);
}
}
///
/// Stores the collection of Axes in the Chart.
///
private Collection _axes;
///
/// The collection of foreground elements.
///
private ObservableCollection _foregroundElements = new NoResetObservableCollection();
///
/// The collection of background elements.
///
private ObservableCollection _backgroundElements = new NoResetObservableCollection();
///
/// Gets the collection of foreground elements.
///
ObservableCollection ISeriesHost.ForegroundElements { get { return ForegroundElements; } }
///
/// Gets the collection of foreground elements.
///
protected ObservableCollection ForegroundElements { get { return _foregroundElements; } }
///
/// Gets the collection of background elements.
///
ObservableCollection ISeriesHost.BackgroundElements { get { return BackgroundElements; } }
///
/// Gets the collection of background elements.
///
protected ObservableCollection BackgroundElements { get { return _backgroundElements; } }
///
/// Axes arranged along the edges.
///
private ObservableCollection _edgeAxes = new NoResetObservableCollection();
///
/// Gets or sets the axes that are currently in the chart.
///
private IList InternalActualAxes { get; set; }
///
/// Gets the actual axes displayed in the chart.
///
public ReadOnlyCollection ActualAxes { get; private set; }
///
/// Gets or sets the reference to the template's ChartArea.
///
private EdgePanel ChartArea { get; set; }
///
/// Gets or sets the reference to the Chart's Legend.
///
private Legend Legend { get; set; }
///
/// Gets or sets the collection of Series displayed by the Chart.
///
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Setter is public to work around a limitation with the XAML editing tools.")]
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "value", Justification = "Setter is public to work around a limitation with the XAML editing tools.")]
public Collection Series
{
get
{
return _series;
}
set
{
throw new NotSupportedException(Properties.Resources.Chart_Series_SetterNotSupported);
}
}
///
/// Stores the collection of Series displayed by the Chart.
///
private Collection _series;
#region public Style ChartAreaStyle
///
/// Gets or sets the Style of the ISeriesHost's ChartArea.
///
public Style ChartAreaStyle
{
get { return GetValue(ChartAreaStyleProperty) as Style; }
set { SetValue(ChartAreaStyleProperty, value); }
}
///
/// Identifies the ChartAreaStyle dependency property.
///
public static readonly DependencyProperty ChartAreaStyleProperty =
DependencyProperty.Register(
"ChartAreaStyle",
typeof(Style),
typeof(Chart),
null);
#endregion public Style ChartAreaStyle
///
/// Gets the collection of legend items.
///
public Collection