using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; namespace Microsoft.Research.DynamicDataDisplay.Charts.Axes.GenericLocational { public class GenericLocationalLabelProvider : LabelProviderBase { private readonly IList collection; private readonly Func displayMemberMapping; public GenericLocationalLabelProvider(IList collection, Func displayMemberMapping) { if (collection == null) throw new ArgumentNullException("collection"); if (displayMemberMapping == null) throw new ArgumentNullException("displayMemberMapping"); this.collection = collection; this.displayMemberMapping = displayMemberMapping; } int startIndex; public override UIElement[] CreateLabels(ITicksInfo ticksInfo) { var ticks = ticksInfo.Ticks; if (ticks.Length == 0) return EmptyLabelsArray; startIndex = (int)ticksInfo.Info; UIElement[] result = new UIElement[ticks.Length]; LabelTickInfo labelInfo = new LabelTickInfo { Info = ticksInfo.Info }; for (int i = 0; i < result.Length; i++) { var tick = ticks[i]; labelInfo.Tick = tick; labelInfo.Index = i; string labelText = GetString(labelInfo); TextBlock label = new TextBlock { Text = labelText }; ApplyCustomView(labelInfo, label); result[i] = label; } return result; } protected override string GetStringCore(LabelTickInfo tickInfo) { return displayMemberMapping(collection[tickInfo.Index + startIndex]); } } }