私は現在のプロジェクトでまったく同じことをしているので、関連するコードをコピーして貼り付けます。activeWpfTextView
次の回答を使用して、別の場所にオブジェクトを生成します: VS 2010 RC 拡張機能で特定の ProjectItem の IVsTextView または IWpfTextView を検索します。
private IVsWindowFrame GetWindow()
{
// parent is the Microsoft.VisualStudio.Shell.ToolWindowPane
// containing this UserControl given in the constructor.
var window = (ToolWindowPane)parent.GetIVsWindowPane();
return (IVsWindowFrame)window.Frame;
}
private void DoShow()
{
var window = GetWindow();
var textViewOrigin = (activeWpfTextView as UIElement).PointToScreen(new Point(0, 0));
var caretPos = activeWpfTextView.Caret.Position.BufferPosition;
var charBounds = activeWpfTextView
.GetTextViewLineContainingBufferPosition(caretPos)
.GetCharacterBounds(caretPos);
double textBottom = charBounds.Bottom;
double textX = charBounds.Right;
Guid guid = default(Guid);
double newLeft = textViewOrigin.X + textX - activeWpfTextView.ViewportLeft;
double newTop = textViewOrigin.Y + textBottom - activeWpfTextView.ViewportTop;
window.SetFramePos(VSSETFRAMEPOS.SFP_fMove, ref guid,
(int)newLeft, (int)newTop,
0, 0);
window.Show();
resultsList.Focus();
}