private void AssociatedObject_PreviewKeyDown(object sender, KeyEventArgs e) { if (!AutoCompletePopup.IsOpen) { return; } bool close = false; switch (e.Key) { case Key.Escape: close = true; break; case Key.Return: InsertText(); close = true; break; case Key.Up: AutoCompleteBox.SelectedIndex--; e.Handled = true; break; case Key.Down: AutoCompleteBox.SelectedIndex++; e.Handled = true; break; case Key.Back: if (FilterText.Length > 0) { FilterText = FilterText.Substring(0, FilterText.Length - 1); } else { close = true; } break; } int itemCount = FilteredItems.Count(); if (AutoCompleteBox.SelectedIndex < 0) { AutoCompleteBox.SelectedIndex = itemCount - 1; } if (AutoCompleteBox.SelectedIndex >= itemCount) { AutoCompleteBox.SelectedIndex = 0; } if (close) { e.Handled = true; CloseAutoCompleteBox(); } }
/// <summary> /// Populates the list of filter vars with those that match the VarNames found in the provided list of questions. /// </summary> /// <param name="questions"></param> private void GetFilterVars(List <SurveyQuestion> questions) { string filterVar; int filterVarPos = 0; int filterVarLen; string filterExp; // the filter expression of the variable e.g. [varname]=1, 2, 8 or 9. string[] filterOptionsList; string options; Regex rx; MatchCollection results; while (!FilterText.Equals("")) { FilterVar fv; foreach (SurveyQuestion q in questions) { filterVar = q.VarName.RefVarName; if (!FilterText.Contains(filterVar)) { continue; } rx = new Regex(filterVar + "(=|<|>|<>)" + "(([0-9]+(,\\s[0-9]+)+\\sor\\s[0-9]+)" + "|([0-9]+\\sor\\s[0-9]+)" + "|([0-9]+\\-[0-9]+)" + "|([0-9]+))"); filterVarPos = FilterText.IndexOf(filterVar); filterVarLen = filterVar.Length; results = rx.Matches(FilterText); if (results.Count > 0) { filterExp = results[0].Value; options = filterExp.Substring(filterVarLen + 1); options = Regex.Replace(options, "[^0-9 <->]", ""); filterOptionsList = GetOptionList(options).Split(' '); fv = new FilterVar(); fv.Varname = filterVar; if (filterOptionsList.Length != 0) { fv.ResponseCodes = filterOptionsList.Select(Int32.Parse).ToList(); } // add to the list of filter vars if it is not already there if (!FilterVars.Contains(fv)) { FilterVars.Add(fv); } } else { filterVarPos = 0; continue; } filterVarPos = 0; // trim the filterText to the point after this VarName FilterText = FilterText.Substring(filterVarPos + filterVarLen); } if (filterVarPos == 0) { break; } } }