问题
I added usercontrol (textbox) in code editor control. But textbox not handle any keys (arrow, backspace). Keys handle code editor only. Example:
get IWpfTextView
var textManager = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));
IVsTextView textView;
textManager.GetActiveView(1, null, out textView);
var userData = (IVsUserData)textView;
if (userData == null)
return null;
Guid guidWpfViewHost = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost;
object host;
userData.GetData(ref guidWpfViewHost, out host);
return ((IWpfTextViewHost)host).TextView;
Add control with textbox
Canvas.SetLeft(_control, _view.ViewportRight - 255);
Canvas.SetTop(_control, _view.ViewportTop + 10);
(((System.Windows.Controls.ContentControl)_view).Content as Canvas).Children.Add(_control);
But there was a problem when processing keys, their intercepts (the main window as the editor), keys are not processed. For example arrows, HOME and other. If so add a textbox, then the letters are printed there. But the other key is handled by the editor, rather than this text box even backspace. Who knows how to catch and handle correctly?
来源:https://stackoverflow.com/questions/21132095/how-to-handle-pressing-any-keys-in-the-user-control-in-visual-studio-vspackage