You need to create a UITypeEditor
. The following is a template for a combox editor:-
public class MyCustomEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider)
{
var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
var list = new ListBox();
// Your code here to populate the list box with your items
EventHandler onclick = (sender, e) => {
editiorService.CloseDropDown();
};
list.Click += onclick;
myEditorService.DropDownControl(list);
list.Click -= onclick;
return (list.SelectedItem != null) ? list.SelectedItem : Guid.Empty;
}
}
On your property in the activity:-
[Editor(typeof(MyCustomEditor), typeof(UITypeEditor)]
public Guid MyGuidValue
{
get { return (Guid)GetValue(MyGuidValueProperty); }
set { SetValue(MyGuidValueProperty, value); }
}
- The
Editor
attribute will tell the PropertyGrid that you have created a custom editor for this property.
- The
GetEditStyle
method of the Editor tells the property grid to display a drop down button on the propery value.
- When clicked the property grid calls the custom editor's
EditValue
method.
- The editor service is used to display a drop down with the
DropDownControl
method which takes a control that is to be display in the drop down area.
- The
DropDownControl
method will block until the editor service CloseDropDown
method is called.