我在做一個當前項目中完全一樣的東西,所以這裏是相關的代碼複製和粘貼。我使用以下答案在其他地方生成了activeWpfTextView
對象:Find an IVsTextView or IWpfTextView for a given ProjectItem, in VS 2010 RC extension。
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();
}
此代碼中的「父」是什麼? – 2015-09-30 14:52:08
在代碼中增加了一條註釋,說明「父」來自哪裏。 – perelman 2016-01-31 09:54:22