可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm creating a Visual Studio package that exposes a tool window and I'm trying to make sure that it is displayed docked to the left edge of the main Visual Studio window when the package first loads.
[ProvideToolWindow(typeof(MyToolWindow), Orientation = ToolWindowOrientation.Left,
Style=VsDockStyle.Linked, Window=EnvDTE.Constants.vsWindowKindLinkedWindowFrame)])]
[ProvideToolWindowVisibility(typeof(MyToolWindow), VSConstants.UICONTEXT.NoSolution_string)]
public class MyPackage : Package
{
...
I've tried many variations of the above, but the best I've managed to achieve is having the window docked to the bottom - and even then it keeps on re-docking every time the package is re-loaded rather than persisting the user window position.
How can I specify that my window pane be initially shown docked to the left of the main window?
回答1:
Setting up items as VsDockStyle.Tabbed is supported, so you could hook onto the Toolbox tool window. But I'm guessing you already thought of that and it doesn't fit your situation.
Although not a pretty solution, you could try this workaround.
Setup the ProvideToolWindow with the Orientation and Window you want, but set the Style to Float since Linked is not supported (http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.vsdockstyle.aspx):
[ProvideToolWindow(typeof(MyToolWindow), Style = VsDockStyle.Float, Orientation = ToolWindowOrientation.Left, Window = EnvDTE.Constants.vsWindowKindMainWindow)]
At run time, dock the tool window if you find it in a floating state:
/// <summary>
/// Docks the specified frame window if it is currently floating.
/// </summary>
/// <remarks>
/// Works in VS2010, does not appear to work in VS2008.
/// </remarks>
/// <param name="frame">The frame.</param>
private static void DockWindowIfFloating(IVsWindowFrame frame)
{
// Get the current tool window frame mode.
object currentFrameMode;
frame.GetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, out currentFrameMode);
// If currently floating, switch to dock mode.
if ((VSFRAMEMODE)currentFrameMode == VSFRAMEMODE.VSFM_Float)
{
frame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_Dock);
}
}
As I noted in the remarks - this only seems to work for VS2010 (not VS2008).
Hope it helps, hacky as it is.
回答2:
If you want it docked at the bottom by default with the other windows like the Output Window, Error List, Find Results, etc. you can do it like this:
[ProvideToolWindow(typeof(ThePane),
Orientation=ToolWindowOrientation.Right,
Window=EnvDTE.Constants.vsWindowKindOutput,
Style=VsDockStyle.Tabbed)]
The orientation doesn't seem to make a difference, though, it always seems to appear on the left. But close enough for me.
回答3:
I don't know if this works, but you can give it a try:
I looked in the registry for a clue, to where the SolutionExplorer toolwindow is docked and
found that the Window parameter contains "DocumentWell"
So you can try this:
[ProvideToolWindow(typeof(MyToolWindow), Orientation = ToolWindowOrientation.Right, Style=VsDockStyle.Tabbed, Window="DocumentWell")])]
or
Window=EnvDTE.Constants.vsWindowKindMainWindow
Hope this helps,
Thomas.
回答4:
// Replace EnvDTE.Constants.vsWindowKindSolutionExplorer with the GUID you need.
[ProvideToolWindow(typeof(IssuesWindow), Style = VsDockStyle.Tabbed, Window = EnvDTE.Constants.vsWindowKindSolutionExplorer)]
This works fine on Visual Studio 2015. Tested on a virtual machine.
However, there is a limitation: The tool window only gets docked for the very first time the IDE starts with your extension. It's easy to test with a virtual machine, as you just restore a previous state. I guess some registry value is written and Visual Studio rather remembers the previous position of your tool window next time rather than using the defaults you've just specified above.
If someone wants, I guess they could compare before/after versions of the registry and find these set values and reset them manually next time/on demand.