.net 如何公开派生FileNodeProperties属性的自定义编辑器
我正在使用托管包框架MPF为Visual Studio 2013创建自定义项目解决方案。我已经成功地为我的项目和文件节点创建了自定义节点类型,并公开了自定义FileNodeProperties 在MPF中,我发现我可以在我的FileNodeProperties中公开一个类型为集合的属性,这样,当项目正在运行并且我在解决方案资源管理器中选择文件节点时,该属性将显示在属性窗口中,并带有一个尾部[…]按钮,单击该按钮时会显示标准集合编辑器对话框 我在网上搜索过各种强积金网站,如.net 如何公开派生FileNodeProperties属性的自定义编辑器,.net,vsx,vspackage,vs-extensibility,mpf,.net,Vsx,Vspackage,Vs Extensibility,Mpf,我正在使用托管包框架MPF为Visual Studio 2013创建自定义项目解决方案。我已经成功地为我的项目和文件节点创建了自定义节点类型,并公开了自定义FileNodeProperties 在MPF中,我发现我可以在我的FileNodeProperties中公开一个类型为集合的属性,这样,当项目正在运行并且我在解决方案资源管理器中选择文件节点时,该属性将显示在属性窗口中,并带有一个尾部[…]按钮,单击该按钮时会显示标准集合编辑器对话框 我在网上搜索过各种强积金网站,如 ……但遗憾的是,这毫无
……但遗憾的是,这毫无用处。我怀疑这是一个COM管理的界面,我在某处应用了它?回答了我自己的问题-经过多次试验;审查强积金计划的源代码;还有一些谷歌搜索;我发现必须用一个属性来修饰作为属性公开的类,并创建一个从中派生的自定义编辑器。通常在WinForms中可以找到,它可以在其他地方使用,包括看起来像是定制的项目系统 e、 g.这是表示项目系统中模型文件的文件节点。这里省略了一些代码,尽管不是关键代码。下面的Plugins属性是我希望有一个[…]按钮的属性 这是用于显示和修改插件类型的编辑器
我找到了解决我自己问题的办法,见下面的答案看着落选的选票,考虑到没有接近票数的选票,人们只能假设我是落选狂欢的受害者
[ComVisible(true)]
[CLSCompliant(false)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("x-x-x-x-x")] // obfuscated
internal class ModelFileNodeProperties : FileNodeProperties
{
...
[LocDisplayName("Things")]
public List <int>Things { get; set; }
...
}
[LocDisplayName("SomethingComplex")]
public SomethingComplexWithLotsOfConfig SomethingComplex { get; set; }
[ComVisible(true)]
[CLSCompliant(false)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("xx-xx-xx-xx-xx")]
internal class ModelFileNodeProperties : MbtFileNodeProperties
{
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="ModelFileNodeProperties" /> class.
/// </summary>
/// <param name="node">The node.</param>
public ModelFileNodeProperties(HierarchyNode node) : base(node)
{
Plugins = new Plugins(node); // Our "model" node has a concept of "plug-ins"
}
#endregion
#region Properties
[LocDisplayName("Plugins")]
public Plugins Plugins { get; set; } // <----- I wan't a [...] button for this property
...
}
[Editor(typeof (PluginsEditor), typeof (UITypeEditor))] // <---- MPF will spot this and expose the editor to Visual Studio
internal class Plugins
{
#region Fields
private readonly HierarchyNode _node;
public Plugins(HierarchyNode node) { _node = node; }
// this prevents the object type being displayed in the Property window
public override string ToString() { return "No plug-ins installed"; }
public string Something { get; set; }
public string OrOther { get; set; }
[Microsoft.VisualStudio.Project.LocDisplayName("Things")]
public List<int> Things { get; set; }
#endregion
...
}
internal class PluginsEditor : UITypeEditor
{
public PluginsEditor()
{
}
#region Methods
/// <summary>
/// Edits the specified object's value using the editor style indicated by the
/// <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle" /> method.
/// </summary>
/// <returns>
/// The new value of the object. If the value of the object has not changed, this should return the same object it was
/// passed.
/// </returns>
/// <param name="context">
/// An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that can be used to gain
/// additional context information.
/// </param>
/// <param name="provider">An <see cref="T:System.IServiceProvider" /> that this editor can use to obtain services. </param>
/// <param name="value">The object to edit. </param>
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
var form = new PluginsForm();
form.ShowDialog(); // we want to show a modal dialog
return value;
}
/// <summary>
/// Gets the editor style used by the
/// <see cref="M:System.Drawing.Design.UITypeEditor.EditValue(System.IServiceProvider,System.Object)" /> method.
/// </summary>
/// <returns>
/// A <see cref="T:System.Drawing.Design.UITypeEditorEditStyle" /> value that indicates the style of editor used by the
/// <see cref="M:System.Drawing.Design.UITypeEditor.EditValue(System.IServiceProvider,System.Object)" /> method. If the
/// <see cref="T:System.Drawing.Design.UITypeEditor" /> does not support this method, then
/// <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle" /> will return
/// <see cref="F:System.Drawing.Design.UITypeEditorEditStyle.None" />.
/// </returns>
/// <param name="context">
/// An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that can be used to gain
/// additional context information.
/// </param>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal; // we don't want a drop-down but rather a modal dialog
}
#endregion
}