Host a IWpfTextView in a custom tool for a Visual Studio Extension
- by Adam Driscoll
I'm trying to create a IWpfTextView and then put it into a custom tool window. I can create the view, read a file to populate the ITextBuffer and display the view into my tool.
I cannot edit the code at all and the code is not syntax highlighted. What steps am I missing to make this a full fledged editor?
Code:
IComponentModel componentModel = (IComponentModel)GetGlobalService (typeof(SComponentModel));
var _textEditorFactoryService = componentModel.GetService<ITextEditorFactoryService>();
var _textBufferFactoryService = componentModel.GetService<ITextBufferFactoryService>();
var _contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
TextReader reader = new StreamReader(fileName);
var types = _contentTypeRegistryService.GetContentType("CSharp");
ITextBuffer textBuffer = _textBufferFactoryService.CreateTextBuffer(reader, types);
var view = _textEditorFactoryService.CreateTextView(textBuffer);
IWpfTextViewHost editor = _textEditorFactoryService.CreateTextViewHost(view, true);