I am using AvalonEdit as my TextEditor and is not showing the data in the CodeCompletionWindow when it is called from Key_Down button, however everything works fine when handled as Text_Entered event. Below is the 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;
};
}
}
答案 0 :(得分:3)
得到了答案。在KeyDown事件处理程序中添加了e.Handled = true
。
工作代码。
void TextArea_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
ShowCompletion("");
e.Handled = true;
}
}