// NOTE: In order to change the Title, Maximum, and Minimum properties of the axes, you must handle the Axes_CollectionChanged event.
// However, you only want this event to fire once, so we always remove our handler here, and then re-add it to make sure we don't have
// an ever-increasing number of calls to Axes_CollectionChanged
((ISeriesHost)chart).Axes.CollectionChanged -= new NotifyCollectionChangedEventHandler(Axes_CollectionChanged);
((ISeriesHost)chart).Axes.CollectionChanged +=new NotifyCollectionChangedEventHandler(Axes_CollectionChanged);
}
/// <summary>
/// Handles the CollectionChanged event of the Axes control. Here, X and Y axis titles and min/max properties are set once the graph creates or assigns the axes we need.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="ccEventArgs">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
static void Axes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs ccEventArgs)
{ if (ccEventArgs.Action != NotifyCollectionChangedAction.Remove)
{ Chart chart = null;
foreach (DisplayAxis axis in ccEventArgs.NewItems)
{ chart = (Chart)axis.SeriesHost;
if ((axis.Orientation == AxisOrientation.X && GetSeriesType(chart)!=SeriesType.Bar) || (axis.Orientation == AxisOrientation.Y && GetSeriesType(chart)==SeriesType.Bar))
{ axis.SetBinding(DisplayAxis.TitleProperty, new Binding(GetXAxisTitle(chart)));
if (axis is LinearAxis)
{ axis.SetBinding(LinearAxis.MinimumProperty, new Binding(GetXAxisMinimum(chart)));
axis.SetBinding(LinearAxis.MaximumProperty, new Binding(GetXAxisMaximum(chart)));
}
else if (axis is DateTimeAxis)
{ axis.SetBinding(DateTimeAxis.MinimumProperty, new Binding(GetXAxisMinimum(chart)));
axis.SetBinding(DateTimeAxis.MaximumProperty, new Binding(GetXAxisMaximum(chart)));
}
}
else
{ axis.SetBinding(DisplayAxis.TitleProperty, new Binding(GetYAxisTitle(chart)));
if (axis is LinearAxis)
{ axis.SetBinding(LinearAxis.MinimumProperty, new Binding(GetYAxisMinimum(chart)));
axis.SetBinding(LinearAxis.MaximumProperty, new Binding(GetYAxisMaximum(chart)));
}
else if (axis is DateTimeAxis)
{ axis.SetBinding(DateTimeAxis.MinimumProperty, new Binding(GetYAxisMinimum(chart)));
axis.SetBinding(DateTimeAxis.MaximumProperty, new Binding(GetYAxisMaximum(chart)));
}
}
}
}
}