私自身の質問に答える - 多くの実験の後; プロジェクトソース コードのMPF の検査。そしていくつかのグーグル。Editor属性を持つプロパティとして公開されているクラスを装飾し、UITypeEditorから派生したカスタム エディターを作成する必要があることがわかりました。通常WinForms
、カスタム プロジェクト システムを含む他の場所で使用することができます。
例 これは、プロジェクト システムの「モデル」ファイルを表すファイル ノードです。(ここでは重要ではありませんが、一部のコードは省略されています)。下のPlugins
プロパティは、[...]ボタンが欲しいプロパティです。
[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
次の属性に注意してください。
[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
...
}
Plugins
これは、タイプの表示と変更に使用されるエディターです。
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
}