Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }