Pregunta

I am currently developing a Visual Studio extension, that needs to open a WPF form after firing a menuCommand.

I want to open the form relativly to the caret position, so I need to get the Caret's pixel position. I've checked This article

but it didn't work.

Help please?

¿Fue útil?

Solución

Once you've got a IWpfTextView, you can do view.TextViewLines.GetCaretBounds(view.Caret.Position.BufferPosition) which will give you the position in the "text coordinate system". Adjusting by view.ViewportTop/view.ViewportLeft should give you the position relative to the UIElement that is the view. From there, view.VisualElement.PointToScreen will probably get it to screen coordinates.

I assume you're already figured out that you don't want to embed this UI into the editor directly? Because that's (mildly) easier.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top