Reputation: 39
I have a class with 2 properties which are instances of other classes. The properties themselves show up in the designer but they are empty, they do not show the properties in the classes they represent even though they are marked as Browsable. What am I missing?
Here is the relevant code section of the classes in question and a snapshot of the designer.
`Public Class TextBox
Inherits Windows.Forms.TextBox
Implements IBoundControl(Of String)
Implements ICustomControl
<Browsable(True), Category(CAT)> Public Property Bound As IBinding(Of String) Implements IBoundControl(Of String).Bound
<Browsable(True), Category(CAT)> Public Property Custom As ICustom Implements ICustomControl.Custom
Public Sub New()
Me.Bound = New Binding(Of String)("Text", Me)
Me.Custom = New Custom(Me)
End Sub
End Class
Public Class Custom
Implements ICustom
<Browsable(True), Category(CAT), DefaultValue(XAlign.None)> Public Property HorzAlign As XAlign Implements ICustom.HorzAlign
Get
Return _HorizAlign
End Get
Set(value As XAlign)
_HorizAlign = value
Me.CustomControl.Location = Me.CreatePoint
End Set
End Property
<Browsable(True), Category(CAT), DefaultValue(YAlign.None)> Public Property VertAlign As YAlign Implements ICustom.VertAlign
Get
Return _VertAlign
End Get
Set(value As YAlign)
_VertAlign = value
Me.CustomControl.Location = Me.CreatePoint
End Set
End Property
'.... other methods and properties
End Class
`
Tried adding and removing the designer properties in both classes to no avail. I am definitely missing something. Any help greatly appreciated
This is a VB.NET Desktop application
Upvotes: 0
Views: 55
Reputation: 39
Thanks for the help, it got me going in the right direction. Here is the correct implementation so that it works properly:
Public Class TextBox
Inherits Windows.Forms.TextBox
Implements IBoundControl(Of String)
Implements ICustomControl
<TypeConverter(GetType(ExpandableObjectConverter))>
<Browsable(True), DisplayName("Custom Binding"), Category(CAT),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public Property Bound As IBinding(Of String) Implements IBoundControl(Of String).Bound
<TypeConverter(GetType(ExpandableObjectConverter))>
<Browsable(True), DisplayName("Special Control"), Category(CAT),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public Property Custom As ICustom Implements ICustomControl.Custom
Public Sub New()
Me.Bound = New Binding(Of String)("Text", Me)
Me.Custom = New Custom(Me)
End Sub
End Class
Public Class Binding(Of T)
Implements IBinding(Of T)
Private _BoundPropertyName As String
Private _ErrorLog As ILogBook
Private MyControl As Control
Private MyPropInfo As PropertyInfo
Public Sub New(ByVal pPropertyName As String, ByVal pControl As Control)
Me.MyPropInfo = pControl.GetType.GetProperty(pPropertyName)
Me.MyControl = pControl
End Sub
<NotifyParentProperty(True)>
<Browsable(False)> <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Property ErrorLog As ILogBook Implements IBinding(Of T).ErrorLog
Get
Return _ErrorLog
End Get
Private Set(value As ILogBook)
_ErrorLog = value
End Set
End Property
<NotifyParentProperty(True)>
<Browsable(True), Category(CAT), DefaultValue("")>
Public Property BoundPropertyName As String Implements IBinding(Of T).BoundPropertyName
Get
Return _BoundPropertyName
End Get
Set(value As String)
_BoundPropertyName = value
End Set
End Property
<NotifyParentProperty(True)>
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> Public Property Value As T Implements IBinding(Of T).Value
Get
Return CType(MyPropInfo.GetValue(MyControl), T)
End Get
Set(value As T)
MyPropInfo.SetValue(MyControl, value)
End Set
End Property
Public Overrides Function ToString() As String
Dim TmpName As String = String.Empty
If BoundPropertyName.ToString = String.Empty Then
TmpName = "- Unbound -"
Else
TmpName = BoundPropertyName.ToString
End If
Return String.Format("{0}", TmpName)
End Function
End Class
Upvotes: -1