ta jest szczegółowo wyjaśnione tutaj: WPF in Visual Studio 2010 – Part 4 : Direct Hosting of WPF content
Tak więc, jeśli używasz standardowego rozciągliwość/próbkę Edytor klienta, który pochodzi z Visual Studio SDK, co można zrobić, aby go przetestować jest to,
1) modyfikowanie dostarczonego EditorFactory.cs
pliku tak:
// Create the Document (editor)
//EditorPane NewEditor = new EditorPane(editorPackage); // comment this line
WpfEditorPane NewEditor = new WpfEditorPane(); // add this line
2) CRE jedli na przykład plik WpfEditorPane.cs
takiego:
[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
}
Oczywiście, trzeba będzie wdrożyć wszystkie logiki Editor (dodać interfejsy, itd.), aby naśladować to, co się robi w próbce WinForm, jak to, co dostarczają tutaj naprawdę minimalne rzeczy do czystych celów demonstracyjnych.
UWAGA: cała ta "treść" działa tylko w Visual Studio 2010 (musisz więc upewnić się, że twój projekt odwołuje się do zestawów Visual Studio 2010, co powinno mieć miejsce, jeśli projekt rozpoczniesz od podstaw, używając Visual Studio 2010). Hostowanie edytorów WPF w Visual Studio 2008 jest możliwe przy użyciu System.Windows.Forms.Integration.ElementHost.
W rozszerzeniach VS "Redaktorzy" są zwykle edytorami tekstu/kodu - być może zamiast tego chcesz utworzyć "Projektant". –
Powiązane pytanie: [link] (http://stackoverflow.com/questions/18761221/visual-studio-2012-wpf-custom-design er-editor) – sgnsajgon