我正在创建一个公开工具窗口的 Visual Studio 包,我试图确保它在包首次加载时显示在主 Visual Studio 窗口的左边缘。
[ProvideToolWindow(typeof(MyToolWindow), Orientation = ToolWindowOrientation.Left,
Style=VsDockStyle.Linked, Window=EnvDTE.Constants.vsWindowKindLinkedWindowFrame)])]
[ProvideToolWindowVisibility(typeof(MyToolWindow), VSConstants.UICONTEXT.NoSolution_string)]
public class MyPackage : Package
{
...
我试过 许多 上面的变体,但我设法实现的最好的方法是将窗口停靠在底部 - 即便如此,每次重新加载包时它都会继续重新停靠,而不是保留用户窗口位置。
如何指定我的 Pane 最初显示在主窗口的左侧?
最佳答案
支持将项目设置为 VsDockStyle.Tabbed,因此您可以连接到工具箱工具窗口。但我猜你已经想到了,它不适合你的情况。
虽然不是一个很好的解决方案,但您可以尝试此解决方法。
[ProvideToolWindow(typeof(MyToolWindow), Style = VsDockStyle.Float, Orientation = ToolWindowOrientation.Left, Window = EnvDTE.Constants.vsWindowKindMainWindow)]
/// <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);
}
}
正如我在评论中指出的 - 这似乎只适用于 VS2010(不适用于 VS2008)。
希望它有所帮助,尽管如此。
关于.net - VSX - 设置要停靠的 ToolWindowPanes 初始位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5485491/