// (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;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
namespace System.Windows.Controls.DataVisualization.Charting
{
///
/// This control draws gridlines with the help of an axis.
///
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "GridLine", Justification = "This is the expected capitalization.")]
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "DisplayAxisGridLines", Justification = "This is the expected capitalization.")]
internal abstract class DisplayAxisGridLines : Canvas, IAxisListener
{
#region public DisplayAxis Axis
///
/// The field that stores the axis that the grid lines are connected to.
///
private DisplayAxis _axis;
///
/// Gets the axis that the grid lines are connected to.
///
public DisplayAxis Axis
{
get { return _axis; }
private set
{
if (_axis != value)
{
DisplayAxis oldValue = _axis;
_axis = value;
if (oldValue != _axis)
{
OnAxisPropertyChanged(oldValue, value);
}
}
}
}
///
/// AxisProperty property changed handler.
///
/// Old value.
/// New value.
private void OnAxisPropertyChanged(DisplayAxis oldValue, DisplayAxis newValue)
{
Debug.Assert(newValue != null, "Don't set the axis property to null.");
if (newValue != null)
{
newValue.RegisteredListeners.Add(this);
}
if (oldValue != null)
{
oldValue.RegisteredListeners.Remove(this);
}
}
#endregion public DisplayAxis Axis
///
/// Instantiates a new instance of the DisplayAxisGridLines class.
///
/// The axis used by the DisplayAxisGridLines.
public DisplayAxisGridLines(DisplayAxis axis)
{
this.Axis = axis;
this.SizeChanged += new SizeChangedEventHandler(OnSizeChanged);
}
///
/// Redraws grid lines when the size of the control changes.
///
/// The source of the event.
/// Information about the event.
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
Invalidate();
}
///
/// Redraws grid lines when the axis is invalidated.
///
/// The invalidated axis.
public void AxisInvalidated(IAxis axis)
{
Invalidate();
}
///
/// Draws the grid lines.
///
protected abstract void Invalidate();
}
}