我爲Visual Studio 2008編寫了一個簡單的加載項,用於打開一個可停靠的窗口窗格。爲什麼Visual Studio 2008忘記在哪裏停靠我的加載項窗口窗格?
You can download the source and a binary installer by clicking here.
外接的性質意味着它非常要留位置旁邊的編輯你的源停靠。但有時,在某些安裝中,它不會保持停靠狀態。你運行VS,你停靠我的窗格,你關閉VS,你重新啓動VS,然後它 - 窗格再次浮動。在某些機器上,我必須每次重新停靠它。
但是在其他安裝中,無論我放在哪裏,它都會保持停靠狀態。我原本以爲這可能是Vista和XP之間的區別,但現在我已經報道它也會在XP上脫落。
從我讀過的內容(以及它有時會停靠的事實),我得到了VS應該照顧爲我節省對接狀態的印象。但它沒有這樣做。而同樣的VS安裝中的其他插件沒有這個問題。所以我必須做些事情來改善這種狀況。
我懷疑我的代碼,唯一相關的部分是這樣的:
public class Connect : IDTExtensibility2
{
private static DTE2 _applicationObject;
private AddIn _addInInstance;
private static CodeModelEvents _codeModelEvents;
public static DTE2 VisualStudioApplication
{
get { return _applicationObject; }
}
public static CodeModelEvents CodeModelEvents
{
get { return _codeModelEvents; }
}
public static event EventHandler SourceChanged = delegate { };
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
}
public void OnStartupComplete(ref Array custom)
{
try
{
Events2 events = (Events2)_applicationObject.Events;
_codeModelEvents = events.get_CodeModelEvents(null);
object objTemp = null;
Windows2 toolWins = (Windows2)_applicationObject.Windows;
Window toolWin = toolWins.CreateToolWindow2(
_addInInstance, GetType().Assembly.Location, "Ora.OraPane", "Ora",
"{DC8A399C-D9B3-40f9-90E2-EAA16F0FBF94}", ref objTemp);
toolWin.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
}
public void OnBeginShutdown(ref Array custom) { }
public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { }
public void OnAddInsUpdate(ref Array custom) { }
}
(MSDN文檔表明,窗口應該在的OnConnection被創建,但如果我這樣做,那麼窗口大多不會出現)
感謝這樣一個詳細有用的答案。我真正想要的是讓我的窗格完全停留在用戶放置的位置,但我想我必須一起破解近似的東西。 – 2008-11-25 11:10:44
在這裏開發一個插件。這篇文章完全有幫助。如果它沒有刪除我的投票,它會投兩次票:P。 – 2009-01-22 00:56:24
這個答案很有用,但需要(很多)更多的工作才能讓toolwindow停留在用戶最後離開的地方。 Juozas Kontvainis的答案非常簡單,適用於我(在嘗試了許多其他解決方案之後,其中沒有一個能夠工作)。 – Polyfun 2011-11-04 14:51:44