I've been writing a set of UI controls for use in my upcoming projects, mostly replicating the Visual Studio 2005 look and feel. The rendering is pretty much pixel-perfect, but when using the design-time capabilities of one of my controls (the sidebar), I get an issue when building.
In the .design.cs file of the form, where it sets the properties and whatnot of the SideBar, it puts this line of code:
...
this.sideBar1.Name = "sideBar1";
((Trowbridge.UI.SideBar.SidePanelCollection)(new Trowbridge.UI.SideBar.SidePanel())).Add(this.sidePanel1);
this.sideBar1.SelectedPanel = null;
...
The above code sets off the error at build: Cannot convert type 'Trowbridge.UI.SideBar.SidePanel' to 'Trowbridge.UI.SideBar.SidePanelCollection' (the line between the Name and SelectedPanel sets). Design-time functionality remains intact, the designer is not killed, it just won't build. I have a feeling it has to do with the casts...
The code above is set by the following designer code:
internal class SidePanelCollectionConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
{
if (destType == typeof(InstanceDescriptor))
return true;
return base.CanConvertTo(context, destType);
}
public override object ConvertTo(
ITypeDescriptorContext context,
System.Globalization.CultureInfo culture,
object value, Type destType)
{
if (destType == typeof(InstanceDescriptor))
{
System.Reflection.ConstructorInfo ci = typeof(SidePanel).GetConstructor(System.Type.EmptyTypes);
return new InstanceDescriptor(ci, null, false);
}
return base.ConvertTo(context, culture, value, destType);
}
}
// apoligies for the pink.
// colorized for easier reading
If you'll note the line giving issues, it's making some sort of very strange casts that make no sense whatsoever to me. It looks like it should be this.sideBar1.Add(this.sidePanel1) to me, rather than those set of weird casts.
I am completely stumped. Anyone have any clues?
-Eric
P.S. If anyone cares, this code was based on Tim Dawson's
Creating Collection Controls with Rich Design Time Support article.