在silverlight中以手风琴显示数据 - 数据不显示

时间:2014-10-29 10:41:32

标签: vb.net silverlight-4.0 accordion silverlight-toolkit

环境:silverlight 4.0

我将数据绑定到Silverlight Accodion控件但不显示我的代码数据如下:

<layout:Accordion HorizontalAlignment="Left" Name="accordion1" Width="761" Height="205" Background="SkyBlue" VerticalAlignment="Top" Margin="32,404,0,0">
                            <layout:Accordion.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding ITRUserName}" />
                                    </StackPanel>
                                </DataTemplate>
                            </layout:Accordion.ItemTemplate>
                            <layout:Accordion.ContentTemplate>
                                <DataTemplate> 
                                      <TextBlock Text="{Binding ITRUserName}" /> 
                                </DataTemplate>
                            </layout:Accordion.ContentTemplate>
                        </layout:Accordion> 

xaml.cs:

accordion1.ItemsSource = ITRDescriptionlist

Public Property _itrdescription As New List(Of ITRDescription)
    Public Property ITRDescriptionList() As List(Of ITRDescription)
        Get
            Return _itrdescription
        End Get
        Set(ByVal value As List(Of ITRDescription))
            _itrdescription = value
        End Set
    End Property

Public Class ITRDescription 
    Private Property _ITRDescription As String
    Public Property ITRDescription() As String
        Get
            Return _ITRDescription
        End Get
        Set(ByVal value As String)
            _ITRDescription = value
        End Set
    End Property

    Private Property _ITRDate As String
    Public Property ITRDate() As String
        Get
            Return _ITRDate
        End Get
        Set(ByVal value As String)
            _ITRDate = value
        End Set
    End Property

    Private Property _ITRUsername As String
    Public Property ITRUserName() As String
        Get
            Return _ITRUsername
        End Get
        Set(ByVal value As String)
            _ITRUsername = value
        End Set
    End Property 
End Class

我想显示数据,如下图所示:

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要绑定到包含值的新ITRDescriptionList集合,而不是直接绑定到Property本身。

例如,尝试将它放在xaml.cs中的Public Sub New()中,在InitializeComponent()

Public Sub New()


    InitializeComponent()

    ITRDescriptionList = New List(Of ITRDescription)

    ITRDescriptionList.Add(New ITRDescription With {.ITRDate = Date.Today, .ITRDescription = "Test Description", .ITRUserName = "Joe Bloggs"})

    accordion1.ItemsSource = ITRDescriptionList

End Sub