private void FlagSearchMatches() { if (string.IsNullOrEmpty(SearchTerm)) { foreach (RecentFileWrapper wrapper in RecentFiles) { wrapper.SearchMatch = false; } return; } bool atLeastOneFound = false; foreach (RecentFileWrapper wrapper in RecentFiles) { bool found = !string.IsNullOrEmpty(wrapper.FullDescription) && wrapper.FullDescription.IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0; wrapper.SearchMatch = found; if (found) { atLeastOneFound = true; } } if (atLeastOneFound) { RecentFileWrapper sw = FindNext(false); if (sw == null) { sw = FindPrevious(false); } } }
private RecentFileWrapper FindNextSetting() { ICollectionView dataView = CollectionViewSource.GetDefaultView(RecentFilesList.ItemsSource); IEnumerator enumerator = dataView.GetEnumerator(); RecentFileWrapper firstMatch = null; while (enumerator.MoveNext()) { var current = (RecentFileWrapper)enumerator.Current; if (current.SearchMatch && firstMatch == null) { firstMatch = current; } if (!current.IsSelected) { continue; } // from here we know we are after the selected item while (enumerator.MoveNext()) { current = (RecentFileWrapper)enumerator.Current; if (current.SearchMatch) { return(current); // the first match after the selected item } } return(null); // no match after => we don't cycle } return(firstMatch); // no selection => first one that matched, if any }
private RecentFileWrapper FindPrevious(bool select) { RecentFileWrapper previousMatch = FindPrevSetting(); if (previousMatch != null) { if (select) { previousMatch.IsSelected = true; } else { var listItem = VisualLogicalTreeWalkHelper.FindObjectInVisualTreeWithMatchingType <ListViewItem>( RecentFilesList, child => { object dc = child.GetValue(FrameworkElement.DataContextProperty); return(dc != null && dc == previousMatch); }); if (listItem != null) { listItem.BringIntoView(); } } } else { AudioCues.PlayBeep(); } return(previousMatch); }
private RecentFileWrapper FindPrevSetting() { ICollectionView dataView = CollectionViewSource.GetDefaultView(RecentFilesList.ItemsSource); IEnumerator enumerator = dataView.GetEnumerator(); RecentFileWrapper lastMatch = null; while (enumerator.MoveNext()) { var current = (RecentFileWrapper)enumerator.Current; if (current.IsSelected) { return(lastMatch); } if (current.SearchMatch) { lastMatch = current; } } return(lastMatch); }