IExtenderProvider and Design Time Attributes
Thanks,
Paul Tyng
Thanks,
Paul Tyng
I have a component that implements IExtenderProvider, DataBinder, that provides a "Bindings" property on controls in a form. It initially was designed to only handle one field to property mapping. Of course as soon as I designed it that way it need to handed multiple field to property mappings. A typical collection property built in to the framework renders in the control as and AddRange statement. But since my provided property is not really a property at all but just a get and set method on my DataBinder object I'm not sure exactly how to handle the objects to make the designer function properly for it. Currently it just sets the property to nothing. The collection editor shows up in the designer ui properly and allows me to create my bindings, which also show up in the designer ui properly. The bindings are even written in to the designer code region and their properties set. They are just not added to my collection. I'm not sure exactly how to handle this because every sample, example, howto or post I can find regarding collection properties is only about normal properties, not provided properties.
Paul Tyng
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyCollection GetBindings(Control control)
{
}
Applogies in advance for the horrible name for the attribute.
Assuming we handle this case in the serializer, this should yield the following code in InitializeComponent:
myDataThingy.GetBindings(control1).AddRange(new Binding[] {...});
If it doesn't, let us know and we'll investigate more drastic measures. Worst case, you can replace the serializer for your object. But I like to treat that as a last ditch effort because writing your own serializer is, well, non-trivial.
<ProvideProperty("SomeProperty", GetType(Control))> _
Public Class Extender
Inherits Component
Implements IExtenderProvider
Public Function CanExtend(ByVal extendee As Object) As Boolean Implements System.ComponentModel.IExtenderProvider.CanExtend
Return TypeOf extendee Is TextBox
End Function
'this is the property get
Public Function GetSomeProperty(ByVal ctrl as Control) as String
End Function
'this is the property set
Public Sub SetSomeProperty(ByVal ctrl as Control, ByVal value as String)
End Sub
End Class
In the designer generated code you get something to this effect:
Me.Extender1.SetSomeProperty(Me.TextBox1, "TheValue")
So since its a sub that it is calling in the designer generated code it does not have access to the add range method.
Any other ideas? How would I write my own serializer (I would like to know this regardless :) )
Thanks,
Paul Tyng
Paul Tyng
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Fuction GetSomeProperty(c As Control) As SomeDataType
End Function
Paul
Garick