作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为 Visual Studio 编写编辑器扩展。我已经下载了 VS SDK 并创建了一个新的 Visual Studio 包项目。但是为我创建的虚拟控件是 Windows 窗体控件而不是 WPF 控件。我正在尝试用 WPF 控件替换它,但效果不佳。这有可能吗?
另一个相关问题:是否只能编写文本编辑器?我真正想要的是一个看起来更像具有许多不同字段的表单的编辑器。但这似乎不是为了什么? EditorPane 上有很多接口(interface)仅暗示文本编辑器模型。
理想情况下,我想要一个类似于 resx-editor 的编辑器,其中正在编辑的文件具有 xml-content 并且 editor-ui 不是单个文本框,并且生成的 cs 文件作为子文件输出。这可能与编辑器扩展有关吗?
最佳答案
这里有详细解释: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
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
}
关于wpf - Visual Studio : How to write Editor Extensions with WPF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18761221/
我是一名优秀的程序员,十分优秀!