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