Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Help: Using Style Property

Reply
Thread Tools

Help: Using Style Property

 
 
Ryan
Guest
Posts: n/a
 
      02-28-2007
HELP!!!

I have created a custom contol with the following property:

<TypeConverter(GetType(TypeConverters.StyleConvert er)),
Bindable(True), Category("Header"), Description("HeaderStyle")> _
Public Property HeaderStyle() As Style
Get
EnsureChildControls()
Return lblHeader.ControlStyle
End Get
Set(ByVal value As Style)
Stop
EnsureChildControls()
lblHeader.ControlStyle.CopyFrom(value)
End Set
End Property

The TYPECONVERTER I have added because, without it, when I switch from
design view to source view and back I will get an error about
converting from a string. The problem is I really don't understand
how to use the type converter. I have writen the code below, and not
when I view my control in the designer the nice drop down list of
style attributes is gone. What am I missing?

My TypeConverters.StyleConverter code is below (I have been playing
with it trying to get it to work so please forgive the commented out
code and any STOPS:
--------------------------------
Imports System
Imports System.ComponentModel
Imports System.Globalization
Imports System.Drawing
Imports System.Web.UI.WebControls



Namespace TypeConverters

Public Class StyleConverter
Inherits ExpandableObjectConverter

' Overrides the CanConvertFrom method of TypeConverter.
' The ITypeDescriptorContext interface provides the context
for the
' conversion. Typically, this interface is used at design time
to
' provide information about the design-time container.

Public Overrides Function CanConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As
System.Type) As Boolean
If destinationType Is GetType(String) Then
Return True
End If
Return MyBase.CanConvertTo(context, destinationType)
End Function
Public Overloads Overrides Function CanConvertFrom(ByVal
context As ITypeDescriptorContext, ByVal sourceType As Type) As
Boolean
If sourceType Is GetType(Style) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function

Public Overrides Function GetCreateInstanceSupported(ByVal
context As ITypeDescriptorContext) As Boolean
' Always force a new instance
Return True
End Function


' Overrides the CreateInstance method of
ExpandableTypeConverter
Public Overrides Function CreateInstance(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal propertyValues As
System.Collections.IDictionary) As Object
Stop
Return New Style
End Function

Public Overloads Function ConvertTo(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As
Object) As Object
'Do I need this? Should it be Overloads?

End Function

' Overrides the ConvertFrom method of ExpandableTypeConverter.
Public Overloads Overrides Function ConvertFrom(ByVal context
As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value
As Object) As Object
If TypeOf value Is String Then
' Dim item As Object
Dim thisStyle As New Style
'thisStyle.BackColor
'thisStyle.BorderColor
'thisStyle.BorderStyle
'thisStyle.CssClass
'thisStyle.Font.Names
'thisStyle.Font.Name
'thisStyle.Font.Overline
'thisStyle.ForeColor
'thisStyle.Height
'thisStyle.Font.Size
' For Each item In value
' thisstyle.
' Next
' Dim v As String() =
CStr(value).Split(New Char() {";"})
' For Each item In v
' thisStyle.Container.Add(item)
' Next
Return thisStyle
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function

' Overrides the ConvertTo method of ExpandableTypeConverter.
Public Overloads Overrides Function ConvertTo(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As
Object, ByVal destinationType As Type) As Object
If destinationType Is GetType(String) Then
Dim str As String
Dim item As Object
str = ""
For Each item In value.container
str = str & item.ToString & ";"
Next
Return str
End If
Return MyBase.ConvertTo(context, culture, value,
destinationType)
End Function
End Class


End Namespace

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a method into a property without using the @property decorator Phlip Python 2 10-23-2010 05:25 PM
Setting the value of a Master page's control's property using a property of the Master page Nathan Sokalski ASP .Net 25 03-04-2010 03:42 AM
using the Items property in the design time property window Ryan Taylor ASP .Net Building Controls 4 02-18-2005 01:50 PM
When/Should we use CssClass property or Style property? Sky ASP .Net Web Controls 2 10-01-2004 07:38 AM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM



Advertisments