My custom web/server-side combobox component, written in VB.NET, and has four style properties,each of which I want to be able to editusing the built-in style editor when the user clicks these properties in the Designer's Property Windows.
How can I set this up?
Also, I'm using CategoryAttribute.Design to make Style appear in the Design group of the property window, but VS.NET's help seems to indicate that you can put in in any category, including a custom one such as "Component", but it doesn't show how to do this.
Anyone know how I can do this?
Here is thecode frommy Design Time render class thatexposes the Style property and makes it appear in the property window:
Private Property [Style]() As System.Web.UI.CssStyleCollection
Get
Dim cbx As cwcComboBox = CType(Me.Component, cwcComboBox)
Return cbx.Style
End Get
Set
Dim cbx As cwcComboBox = CType( Me.Component, cwcComboBox )
' copy the attributesfrom the Value CssStyleCollection to
'the Style CssStyleCollection.
cbx.ApplyCssStyleCollectionToCssStyleCollection( Value, cbx.Style )
End Set
End Property ' End of Style
Protected Overrides Sub PreFilterProperties( ByVal properties AsIDictionary )
MyBase.PreFilterProperties( properties )
'
' Modify Style property to allow it to be seen in the Designer Properity window
'
properties( "Style" ) = _
TypeDescriptor.CreateProperty( _
Me.GetType(), _
"Style", _
Style.GetType(), _
CategoryAttribute.Design, _
DesignOnlyAttribute.No )
End Sub ' End of PreFilterProperties
For completeness, here is the codefor ApplyCssStyleCollectionToCssStyleCollection from my cwcComboBox component class,referenced by cbx above:
'
'ApplyCssStyleCollectionToCssStyleCollection
'
'Copy the attribute members from the SrcCssStyleCollection set
'to the DestCssStyleCollection.
'
'The optionalMode parameter accepts Replace or Add
' Replaceoptionclears the DestCssStyleCollection before
' copying the attributes from SrcCssStyleCollection.
' Add option just copies the SrcCssStyleCollection attributes
' to DestCssStyleCollection, overwriting any that may
' already exist.
'
Public Sub ApplyCssStyleCollectionToCssStyleCollection( _
ByRef SrcCssStyleCollection As System.Web.UI.CssStyleCollection, _
ByRef DestCssStyleCollection As System.Web.UI.CssStyleCollection, _
Optional ByVal Mode As String = "REPLACE" )
Dim KeyName As String
Dim KeyValue As String
Dim OldKeyValue As String
If Mode.ToUpper <> "REPLACE" And Mode.ToUpper <> "ADD" Then
MsgBox( "Invalid Mode, it must either be Replace or Add.", _
MsgBoxStyle.OKOnly, _
"ApplyCssStyleCollectionToCssStyleCollection" )
ElseIf SrcCssStyleCollection Is Nothing Then
MsgBox( "Source CSS Style misssing", _
MsgBoxStyle.OKOnly, _
"ApplyCssStyleCollectionToCssStyleCollection" )
ElseIf DestCssStyleCollection Is Nothing Then
MsgBox( "Destination CSS Style misssing", _
MsgBoxStyle.OKOnly, _
"ApplyCssStyleCollectionToCssStyleCollection" )
Else
If SrcCssStyleCollection.Count > 0 Then
Dim Keys( SrcCssStyleCollection.Count - 1 ) As String
Dim KeyCounter As Integer = 0
For Each KeyName In SrcCssStyleCollection.Keys
If KeyName <> "" Then
Keys( KeyCounter ) = KeyName
KeyCounter += 1
End If
Next
If Mode.ToUpper = "REPLACE" Then
DestCssStyleCollection.Clear()
End If
For Each KeyName In Keys
KeyValue =SrcCssStyleCollection( KeyName )
OldKeyValue = DestCssStyleCollection( KeyName )
' if the key doesn't already exist, add it, otherwise update it.
If Not OldKeyValue Is NothingThen
DestCssStyleCollection.Add( KeyName, KeyValue )
ElseIf KeyValue <> OldKeyValueThen
DestCssStyleCollection( KeyName ) = KeyValue
End If
Next
End If
End If
End Sub ' End of ApplyCssStyleCollectionToCssStyleCollection
Thank you