Host a IWpfTextView in a custom tool for a Visual Studio Extension
Posted
by Adam Driscoll
on Stack Overflow
See other posts from Stack Overflow
or by Adam Driscoll
Published on 2010-04-07T03:16:26Z
Indexed on
2010/04/07
3:23 UTC
Read the original article
Hit count: 1108
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);
© Stack Overflow or respective owner