中對此有詳細說明如下:WPF in Visual Studio 2010 – Part 4 : Direct Hosting of WPF content
所以,如果你使用標準的可擴展性/自定義編輯器樣品隨Visual Studio的SDK,你可以做些什麼來測試它是這樣的:
1)修改提供EditorFactory.cs
文件是這樣的:
// Create the Document (editor)
//EditorPane NewEditor = new EditorPane(editorPackage); // comment this line
WpfEditorPane NewEditor = new WpfEditorPane(); // add this line
2)CRE吃例如WpfEditorPane.cs
文件是這樣的:
[ComVisible(true)]
public class WpfEditorPane : WindowPane, IVsPersistDocData
{
private TextBox _text;
public WpfEditorPane()
: base(null)
{
_text = new TextBox(); // Note this is the standard WPF thingy, not the Winforms one
_text.Text = "hello world";
Content = _text; // use any FrameworkElement-based class here.
}
#region IVsPersistDocData Members
// NOTE: these need to be implemented properly! following is just a sample
public int Close()
{
return VSConstants.S_OK;
}
public int GetGuidEditorType(out Guid pClassID)
{
pClassID = Guid.Empty;
return VSConstants.S_OK;
}
public int IsDocDataDirty(out int pfDirty)
{
pfDirty = 0;
return VSConstants.S_OK;
}
public int IsDocDataReloadable(out int pfReloadable)
{
pfReloadable = 0;
return VSConstants.S_OK;
}
public int LoadDocData(string pszMkDocument)
{
return VSConstants.S_OK;
}
public int OnRegisterDocData(uint docCookie, IVsHierarchy pHierNew, uint itemidNew)
{
return VSConstants.S_OK;
}
public int ReloadDocData(uint grfFlags)
{
return VSConstants.S_OK;
}
public int RenameDocData(uint grfAttribs, IVsHierarchy pHierNew, uint itemidNew, string pszMkDocumentNew)
{
return VSConstants.S_OK;
}
public int SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
{
pbstrMkDocumentNew = null;
pfSaveCanceled = 0;
return VSConstants.S_OK;
}
public int SetUntitledDocPath(string pszDocDataPath)
{
return VSConstants.S_OK;
}
#endregion
}
當然,你將必須實現所有的編輯邏輯(添加接口等),以模仿有什麼的WinForms樣品中完成的,因爲我在這裏提供的真正用於純演示目的的最低限度的東西。
注意:這整個「內容」的東西只適用於從Visual Studio 2010開始(所以你需要確保你的項目引用Visual Studio 2010程序集,如果你使用Visual Studio 2010從頭開始一個項目應該是這種情況)。使用System.Windows.Forms.Integration.ElementHost可以在Visual Studio 2008中託管WPF編輯器。
在VS Extensions中,「編輯者」一般是文本/代碼編輯器 - 也許你想創建一個「設計器」來代替。 – 2012-01-02 23:26:19
相關問題:[鏈接](http://stackoverflow.com/questions/18761221/visual-studio-2012-wpf-custom-design er-editor) – sgnsajgon 2013-09-12 12:56:27