When a component implements ICustomTypeDescriptor, its component
designer is ignored by the IDE. Just remove the ICustomTypeDescriptor
implementation in the above sample makes the component designer works
again.
I tried several implementation of ICustomTypeDescriptor without
success. Is it incompatible with ComponentDesigner?
Code Sample:
internal class MyDesigner : ComponentDesigner
{
public override System.ComponentModel.Design.DesignerVerbCollection
Verbs
{
get
{
return new DesignerVerbCollection( new DesignerVerb[] { new
DesignerVerb("Example Designer Verb Command", new
EventHandler(this.onVerb)) } );
}
}
private void onVerb(object sender, EventArgs e)
{
MessageBox.Show("The event handler for the Example Designer Verb
Command was invoked.");
}
}
[Designer(typeof(MyDesigner))]
public class MyComponent : IComponent, ICustomTypeDescriptor
{
// IComponent and IDisposable implementation removed
#region ICustomTypeDescriptor Members
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return null;
}
EventDescriptorCollection
ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
{
return EventDescriptorCollection.Empty;
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
{
return EventDescriptorCollection.Empty;
}
string ICustomTypeDescriptor.GetComponentName()
{
return "MyComponent";
}
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor
pd)
{
return this;
}
AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
// if( site != null && site.DesignMode )
// {
// object[] attributes =
this.GetType().GetCustomAttributes(true);
// Attribute[] cattributes = attributes as Attribute[];
// if( cattributes != null)
// return new AttributeCollection(cattributes);
// }
//
return AttributeCollection.Empty;
}
PropertyDescriptorCollection
ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
{
return (this as ICustomTypeDescriptor).GetProperties();
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
// if( site != null && site.DesignMode )
// return TypeDescriptor.GetProperties( this, true );
//
return TypeDescriptor.GetProperties(typeof(DateTime));
}
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return null;
}
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
{
return null;
}
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
{
return null;
}
string ICustomTypeDescriptor.GetClassName()
{
return "MyComponent";
}
#endregion
}
Thierry - 01 Sep 2005 20:55 GMT
The following implementation of ICustomTypeDescriptor fix the problem:
AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
if( site != null && site.DesignMode )
{
object[] attributes = this.GetType().GetCustomAttributes(true);
Attribute[] cattributes = new Attribute[ attributes.Length ];
attributes.CopyTo( cattributes, 0);
return new AttributeCollection(cattributes);
}
return AttributeCollection.Empty;
}