コード例 #1
0
        private void Search(object sender, EventArgs eventArgs)
        {
            if (!searchPending)
            {
                return;
            }

            if (!SearchEnabled)
            {
                return;
            }

            if (WordList == null)
            {
                return;
            }

            searchPending = false;

            string searchText = (SearchText ?? "").Trim();

            IEnumerable <WordForm> forms         = WordList.GetAllForms();
            List <WordForm>        filteredForms = forms.Where(w => w.Name.StartsWith(searchText, true, CultureInfo.InvariantCulture)).OrderBy(w => w.Name).ToList();
            WordForm matchingWordForm            = null;

            foreach (WordForm wordForm in filteredForms)
            {
                if (wordForm.Name.Equals(searchText, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (matchingWordForm == null || wordForm.WordInfo.Word.Name.Equals(searchText, StringComparison.InvariantCultureIgnoreCase))
                    {
                        matchingWordForm = wordForm;
                    }
                }
            }
            MatchingWords = new ObservableCollection <WordForm>(filteredForms);
            if (matchingWordForm != null)
            {
                CurrentWordForm = matchingWordForm;
            }
        }