private void FlagSearchMatches() { if (string.IsNullOrEmpty(SearchTerm)) { foreach (SettingWrapper wrapper in AggregatedSettings) { wrapper.SearchMatch = false; } return; } bool atLeastOneFound = false; foreach (SettingWrapper wrapper in AggregatedSettings) { bool found = !string.IsNullOrEmpty(wrapper.Name) && wrapper.Name.IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0; wrapper.SearchMatch = found; if (found) { atLeastOneFound = true; } } if (atLeastOneFound) { SettingWrapper sw = FindNext(false); if (sw == null) { sw = FindPrevious(false); } } }
private SettingWrapper FindNextSetting() { ICollectionView dataView = CollectionViewSource.GetDefaultView(SettingsList.ItemsSource); IEnumerator enumerator = dataView.GetEnumerator(); SettingWrapper firstMatch = null; while (enumerator.MoveNext()) { var current = (SettingWrapper)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 = (SettingWrapper)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 SettingWrapper FindPrevious(bool select) { SettingWrapper previousMatch = FindPrevSetting(); if (previousMatch != null) { if (select) { previousMatch.IsSelected = true; } else { var listItem = VisualLogicalTreeWalkHelper.FindObjectInVisualTreeWithMatchingType <ListViewItem>( SettingsList, child => { object dc = child.GetValue(FrameworkElement.DataContextProperty); return(dc != null && dc == previousMatch); }); if (listItem != null) { listItem.BringIntoView(); } } } else { AudioCues.PlayBeep(); } return(previousMatch); }
private SettingWrapper FindPrevSetting() { ICollectionView dataView = CollectionViewSource.GetDefaultView(SettingsList.ItemsSource); IEnumerator enumerator = dataView.GetEnumerator(); SettingWrapper lastMatch = null; while (enumerator.MoveNext()) { var current = (SettingWrapper)enumerator.Current; if (current.IsSelected) { return(lastMatch); } if (current.SearchMatch) { lastMatch = current; } } return(lastMatch); }