Reputation: 6297
Let's say I have a custom activity that has a dependency property of type GUID.
I want in my custom designer to show like a combobox (or my own usercontrol) with possible values to select from (the values should comes from the database).
Is this possible ?
Upvotes: 3
Views: 353
Reputation: 189437
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); }
}
Editor
attribute will tell the PropertyGrid that you have created a custom editor for this property. GetEditStyle
method of the Editor tells the property grid to display a drop down button on the propery value.EditValue
method.DropDownControl
method which takes a control that is to be display in the drop down area.DropDownControl
method will block until the editor service CloseDropDown
method is called.Upvotes: 3