中对此有详细说明如下: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