Ответ 1
Это подробно объясняется здесь: WPF в Visual Studio 2010 - часть 4: прямой хостинг содержимого WPF
Итак, если вы используете стандартную версию Extensibility/Custom Editor, которая поставляется вместе с 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) создайте, например, файл 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), Хостинг редакторов WPF в Visual Studio 2008 возможен с помощью System.Windows.Forms.Integration.ElementHost.