2012-03-08 6 views
2

アイテムと呼ばれるプロパティを持つユーザーコントロールを作成しています。 Itemsは、LibraryPanelBarItemオブジェクトのコレクションを含むLibraryPanelBarItemCollection(カスタムクラス)タイプです。 VSがtreenodes/listviewitemsのようなものを追加するために使用するコレクションエディタを使用して、設計時にこれらを追加できます。理想的には、それらを宣言的にhtml構文に追加することもできます。表示するItemsプロパティを取得できますが、開始タグと終了タグの間にアイテムを追加するインテリセンスはありません。私は、次のプロパティがここ属性コレクションタイプユーザーコントロールのデザイン時に割り当て可能なプロパティ

<ParseChildren(True, "Items")> _ 
Public Class LibraryPanelBar 
Inherits System.Web.UI.UserControl 

<PersistenceMode(PersistenceMode.InnerDefaultProperty)> _ 
<Browsable(True)> _ 
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _ 
Public Property Items As LibraryPanelBarItemCollection 

...Do Some Stuff... 

End Class 

と宣言している私のユーザーコントロールで

はLibraryPanelBarItemとLibraryPanelBarItemCollection

Public Class LibraryPanelBarItem 
<BindableAttribute(True)> _ 
Public Property ImageUrl As String 

<BindableAttribute(True)> _ 
Public Property NavigateUrl As String 
Public Property Text As String 
Public Property Disabled As Boolean 
Public Property ID As String 
<PersistenceMode(PersistenceMode.InnerDefaultProperty)> _ 
Public Property Items As LibraryPanelBarItemCollection 
Public ReadOnly Property HasChildren() As Boolean 
    Get 
     If Items.Count > 0 Then 
      Return True 
     Else 
      Return False 
     End If 
    End Get 
End Property 


Public Sub New() 
    Items = New LibraryPanelBarItemCollection 
End Sub 
End Class 

Public Class LibraryPanelBarItemCollection 
Inherits CollectionBase 

Default Public ReadOnly Property Item(Index As Integer) As LibraryPanelBarItem 
    Get 
     Return DirectCast(List(Index), LibraryPanelBarItem) 
    End Get 
End Property 

Public Function Contains(itemType As LibraryPanelBarItem) As Boolean 
    Return List.Contains(itemType) 
End Function 

Public Function Add(itemType As LibraryPanelBarItem) As Integer 
    Return List.Add(itemType) 
End Function 

Public Sub Remove(itemType As LibraryPanelBarItem) 
    List.Remove(itemType) 
End Sub 

Public Sub Insert(index As Integer, itemType As LibraryPanelBarItem) 
    List.Insert(index, itemType) 
End Sub 

Public Function IndexOf(itemType As LibraryPanelBarItem) As Integer 
    Return List.IndexOf(itemType) 
End Function 

Public Sub New() 

End Sub 
End Class 

のための私のカスタムクラスは、ここにあるのaspxファイル内の私の現在の宣言です:

<uc1:LibraryPanelBar ID="LibraryPanelBar2" runat="server"> 
    <Items> 
    </Items> 
</uc1:LibraryPanelBar> 
+0

まず、 'LibraryPanelBarItem'がそれ自身の再帰的リストを持つつもりでしたか? –

+0

はい、LibraryPanelBarItemsには、LibraryPanelBarItemsのコレクションを持たせることができます。私がここで作成しようとしているのは、ナビゲーションに使用される一種のメニュー/ Outlookバーです。 – bechbd

答えて

0

以下は、y右方向へのou。詳細が必要な場合は、お気軽にコメントしてください。

<ToolboxData("<{0}:LibraryPanelBar runat=""server""> </{0}:LibraryPanelBar>")> 
Public Class LibraryPanelBar 
    Inherits HierarchicalDataBoundControl 

    Private _Items As New LibraryPanelBarItemCollection() 

    <PersistenceMode(PersistenceMode.InnerProperty)> _ 
    <MergableProperty(False)> _ 
    <Editor("WebApplicationVB1.TreeNodeCollectionEditor,WebApplicationVB1", GetType(UITypeEditor))> _ 
    Public ReadOnly Property Items As LibraryPanelBarItemCollection 
     Get 
      Return _Items 
     End Get 
    End Property 

    Protected Overrides Sub PerformSelect() 

    End Sub 

    Protected Overrides Sub ValidateDataSource(dataSource As Object) 

    End Sub 

    Protected Overrides Sub RenderContents(writer As System.Web.UI.HtmlTextWriter) 
     writer.RenderBeginTag(HtmlTextWriterTag.Ul) 
     For Each item As LibraryPanelBarItem In Items 
      writer.RenderBeginTag(HtmlTextWriterTag.Li) 
      RenderContentsRecursive(writer, item) 
      writer.RenderEndTag() ' Li 
     Next 
     writer.RenderEndTag() ' Ul 
    End Sub 
    Private Sub RenderContentsRecursive(writer As System.Web.UI.HtmlTextWriter, item As LibraryPanelBarItem) 
     writer.Write(item.Text) 
     writer.WriteBreak() 
     writer.RenderBeginTag(HtmlTextWriterTag.Ul) 
     For Each subItem As LibraryPanelBarItem In item.Items 
      writer.RenderBeginTag(HtmlTextWriterTag.Li) 
      RenderContentsRecursive(writer, subItem) 
      writer.RenderEndTag() ' Li 
     Next 
     writer.RenderEndTag() ' Ul 
    End Sub 
End Class 

<ParseChildren(True, "Items")> _ 
Public Class LibraryPanelBarItem 
    Implements IStateManager, ICloneable 

    Private _Items As New LibraryPanelBarItemCollection() 

    <BindableAttribute(True)> _ 
    Public Property ImageUrl As String 

    <BindableAttribute(True)> _ 
    Public Property NavigateUrl As String 
    Public Property Text As String 
    Public Property Disabled As Boolean 
    <Browsable(False)> _ 
<PersistenceMode(PersistenceMode.InnerDefaultProperty)> _ 
    Public ReadOnly Property Items As LibraryPanelBarItemCollection 
     Get 
      Return _Items 
     End Get 
    End Property 
    Public ReadOnly Property HasChildren() As Boolean 
     Get 
      If Items.Count > 0 Then 
       Return True 
      Else 
       Return False 
      End If 
     End Get 
    End Property 

    Public ReadOnly Property IsTrackingViewState As Boolean Implements System.Web.UI.IStateManager.IsTrackingViewState 
     Get 
      Throw New NotImplementedException() 
     End Get 
    End Property 

    Public Sub LoadViewState(state As Object) Implements System.Web.UI.IStateManager.LoadViewState 
     Throw New NotImplementedException() 
    End Sub 

    Public Function SaveViewState() As Object Implements System.Web.UI.IStateManager.SaveViewState 
     Throw New NotImplementedException() 
    End Function 

    Public Sub TrackViewState() Implements System.Web.UI.IStateManager.TrackViewState 
     Throw New NotImplementedException() 
    End Sub 

    Public Function Clone() As Object Implements System.ICloneable.Clone 
     Throw New NotImplementedException() 
    End Function 
End Class 

Public Class LibraryPanelBarItemCollection 
    Inherits CollectionBase 
    Implements IStateManager 

    Default Public ReadOnly Property Item(Index As Integer) As LibraryPanelBarItem 
     Get 
      Return DirectCast(List(Index), LibraryPanelBarItem) 
     End Get 
    End Property 

    Public Function Contains(itemType As LibraryPanelBarItem) As Boolean 
     Return List.Contains(itemType) 
    End Function 

    Public Function Add(itemType As LibraryPanelBarItem) As Integer 
     Return List.Add(itemType) 
    End Function 

    Public Sub Remove(itemType As LibraryPanelBarItem) 
     List.Remove(itemType) 
    End Sub 

    Public Sub Insert(index As Integer, itemType As LibraryPanelBarItem) 
     List.Insert(index, itemType) 
    End Sub 

    Public Function IndexOf(itemType As LibraryPanelBarItem) As Integer 
     Return List.IndexOf(itemType) 
    End Function 

    Public ReadOnly Property IsTrackingViewState As Boolean Implements System.Web.UI.IStateManager.IsTrackingViewState 
     Get 
      Throw New NotImplementedException() 
     End Get 
    End Property 

    Public Sub LoadViewState(state As Object) Implements System.Web.UI.IStateManager.LoadViewState 
     Throw New NotImplementedException() 
    End Sub 

    Public Function SaveViewState() As Object Implements System.Web.UI.IStateManager.SaveViewState 
     Throw New NotImplementedException() 
    End Function 

    Public Sub TrackViewState() Implements System.Web.UI.IStateManager.TrackViewState 
     Throw New NotImplementedException() 
    End Sub 
End Class 

Public Class LibraryPanelBarItemCollectionEditor 
    Inherits System.Drawing.Design.UITypeEditor 

    Public Overrides Function EditValue(context As System.ComponentModel.ITypeDescriptorContext, provider As System.IServiceProvider, value As Object) As Object 
     Return MyBase.EditValue(context, provider, value) 
    End Function 

    Public Overrides Function GetEditStyle(context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle 
     Return MyBase.GetEditStyle(context) 
    End Function 

End Class 

EDIT:追加UIコレクションエディタの例。

+0

デザインタイムコレクションエディタでは、ItemsプロパティにEditorAttributeを追加する必要があります。独自のエディタクラスを作成する必要があります。http://msdn.microsoft.com/en-us/ library/system.web.ui.design.webcontrols.treenodecollectioneditor.aspx –

+0

上記のコメントの例を追加しました。独自の名前空間を指すようにWebApplicationVB1.TreeNodeCollectionEditorを変更する必要があることに注意してください。 –

関連する問題