private void ScrollToLetter(string letter) { if (TargetControl == null || TargetControl.ItemsSource == null) { return; } var collectionView = CollectionViewSource.GetDefaultView(TargetControl.ItemsSource); if (collectionView == null) { throw new InvalidOperationException("The TargetControl should use ICollectionView as ItemSource."); } if (string.IsNullOrEmpty(TargetPropertyPath)) { throw new InvalidOperationException("TargetPropertyPath is not set."); } var firstWithLetter = collectionView.SourceCollection.Cast <object>().FirstOrDefault(o => o.DynamicAccess <string>(TargetPropertyPath)?.StartsWith(letter, true, CultureInfo.InvariantCulture) ?? false); if (firstWithLetter != null) { var scrollViewer = TargetControl.FindChild <ScrollViewer>(); scrollViewer.ScrollToBottom(); TargetControl.ScrollIntoView(firstWithLetter); } }
private void ScrollToMonth(int month) { if (TargetControl == null || TargetControl.ItemsSource == null) { return; } var collectionView = CollectionViewSource.GetDefaultView(TargetControl.ItemsSource); if (collectionView == null) { throw new InvalidOperationException("The TargetControl should use ICollectionView as ItemSource."); } if (string.IsNullOrEmpty(TargetPropertyPath)) { throw new InvalidOperationException("TargetPropertyPath is not set."); } var firstAtMonth = collectionView.SourceCollection.Cast <object>().FirstOrDefault(o => o.DynamicAccess <DateTime?>(TargetPropertyPath)?.Month.Equals(month) ?? false); if (firstAtMonth != null) { var scrollViewer = TargetControl.FindChild <ScrollViewer>(); scrollViewer.ScrollToBottom(); TargetControl.ScrollIntoView(firstAtMonth); } }