I use AvalonEdit as my TextEditor and do not show data in CodeCompletionWindow when it is called from the Key_Down button, however, everything works fine when it is processed as a Text_Entered event. Below is a sample code
[Serializable] public class CodeEditor : TextEditor { public CompletionWindow CompletionWindow = null; public CodeEditor() { //CompletionWindow pops up without any data. this.TextArea.KeyDown += TextArea_KeyDown; //CompletionWindow pops up and data is displayed. this.TextArea.TextEntered += this.OnTextEntered; } void TextArea_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Space && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { ShowCompletion(""); } } void OnTextEntered(object sender, TextCompositionEventArgs e) { //e.Handled = true; if (e.Text == "\n" || e.Text == "\t" || e.Text == " ") { return; } this.ShowCompletion(e.Text); } private void ShowCompletion(string enteredText) { CompletionWindow = new CompletionWindow(TextArea); IList<ICompletionData> data = CompletionWindow.CompletionList.CompletionData; data.Add("ABC"); CompletionWindow.Show(); CompletionWindow.Closed += delegate { CompletionWindow = null; }; } }
source share