private static Visual FindPreviousContainedTarget(Visual scope, Stop currentStop, DependencyProperty navigationModeProperty, IStopComparerProvider stopComparerProvider) { IComparer <Stop> stopComparer = stopComparerProvider.CreateComparer(currentStop); bool passedCurrentStop = false; Stop targetStop = null; foreach (Stop stop in GetContainedStops(scope, currentStop.Element, navigationModeProperty)) { if (stop.Element == currentStop.Element) { passedCurrentStop = true; continue; } int compareResult = stopComparer.Compare(currentStop, stop); if ((compareResult > 0 || compareResult == 0 && !passedCurrentStop) && // select stops with priority lower than currentStop, or the same priority before currentStop (targetStop == null || stopComparer.Compare(targetStop, stop) <= 0)) { targetStop = stop; } } return(targetStop != null ? targetStop.Element : null); }
private static Visual FindLastContainedTarget(Visual scope, Stop currentStop, DependencyProperty navigationModeProperty, IStopComparerProvider stopComparerProvider) { IComparer <Stop> stopComparer = stopComparerProvider.CreateComparer(currentStop); Stop targetStop = null; foreach (Stop stop in GetContainedStops(scope, currentStop.Element, navigationModeProperty)) { if (targetStop == null || stopComparer.Compare(targetStop, stop) <= 0) { targetStop = stop; } } return(targetStop != null ? targetStop.Element : null); }