Display data in accordion in silverlight - data not displaying

42 Views Asked by At

environment : silverlight 4.0

I am binding data to silverlight Accodion control but not displaying data my code as follows :

<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

I want to display data as in the following image :

enter image description here

1

There are 1 best solutions below

0
danielmcn On

You need to bind to new collection of ITRDescriptionList, containing values, rather than directly to the Property itself.

As an example, try putting this in your Public Sub New() in your xaml.cs, under 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