How to handle pressing any keys in the user control in visual studio vspackage

两盒软妹~` 提交于 2019-12-10 19:16:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!