2
사용자 정의 컨트롤에 List (Of Book) 속성을 추가하려고합니다. CollectionEditor에 Book 클래스와 BookCollectionEditor 클래스를 정의했습니다. 또한 사용자 컨트롤을 위해 BookList라는 공용 속성을 정의했습니다. 사용자 정의 컨트롤의 경우 잘 작동하지만 사용자 컨트롤을 위해 디자이너가 내 속성을 표시하지 않습니다. 마크 업에서는 Book 항목을 추가 할 수 있지만 디자이너에게는 오류가 발생합니다. " 'System.Web.UI.UserControl'유형에 'BookList'라는 공용 속성이 없습니다."사용자 컨트롤 목록 속성 디자이너 오류
사용자 정의 컨트롤의 목록 속성을 정의 할 수 있습니까?
<TypeConverter(GetType(ExpandableObjectConverter)), Serializable()> _
Public Class Book
Private _name As String
Private _author As String
Public Sub New()
Me.New(String.Empty, String.Empty)
End Sub
Public Sub New(ByVal name As String, ByVal author As String)
_name = name
_author = author
End Sub
<Category("Book Property"), Description("Name of the Book"), DefaultValue(""), NotifyParentProperty(True)> _
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
<Category("Book Property"), Description("Author of the Book"), DefaultValue(""), NotifyParentProperty(True)> _
Public Property Author() As String
Get
Return _author
End Get
Set(ByVal value As String)
_author = value
End Set
End Property
End Class
Public Class BookCollectionEditor
Inherits CollectionEditor
Public Sub New(ByVal newType As Type)
MyBase.new(newType)
End Sub
Protected Overrides Function CanSelectMultipleInstances() As Boolean
Return False
End Function
Protected Overrides Function CreateCollectionItemType() As Type
Return GetType(Book)
End Function
End Class
Partial Class BooksUserControl
Inherits System.Web.UI.UserControl
Private _booklist As New List(Of Book)
<Category("Behavior"), _
Description("Book List"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
NotifyParentProperty(True), _
PersistenceMode(PersistenceMode.InnerProperty), _
Editor(GetType(BookCollectionEditor), GetType(BookCollectionEditor)), _
Browsable(True)> _
Public ReadOnly Property BookList() As List(Of Book)
Get
If _booklist Is Nothing Then
_booklist = New List(Of Book)()
End If
Return _booklist
End Get
End Property
End Class
Default.aspx를
<uc1:BooksUserControl ID="BooksUserControl1" runat="server">
<BookList>
</BookList>
</uc1:BooksUserControl>
하지만 어떻게 편집기 설정없이 속성 창에서 항목을 추가 할 수 있습니까? – egurer