Load a listbox with two textblock from a database

2019-09-02 02:42发布

问题:

I am trying to load a listbox with two textblock from a database with LINQ in windows phone 7.1. My problem is that data does not appear in the textblock. Maybe the problem is in the xaml code, but I don´t know.

This is the xaml code:

<controls:Pivot Title="CEBADEROS">
        <controls:PivotItem Header="Entradas">
            <ListBox x:Name="EntradasList"
                        Margin="0,0,-12,0">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,17">
                            <TextBlock Text="{Binding Fecha_entrada}"
                                        TextWrapping="NoWrap" Margin="12,0,0,0"
                                        Style="{StaticResource PhoneTextExtraLargeStyle}" Height="60" />
                            <TextBlock Text="{Binding Numero}"
                                        TextWrapping="NoWrap" Margin="12,-6,0,0"
                                        Style="{StaticResource PhoneTextExtraLargeStyle}" Height="60" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </controls:PivotItem>
    </controls:Pivot>

`

I have defined the next class

Public Class ClaseAnimales_Entradas

    Public Property Fecha_Entrada As DateTime
    Public Property numero As Integer

    Sub New()
        MyBase.New()
    End Sub

    Sub New(Fecha_Entrada As DateTime, numero As Integer)
        Me.Fecha_Entrada = Fecha_Entrada
        Me.numero = numero
    End Sub
End Class

And I’m trying to load the list box with the next code:

Partial Public Class GestionPanorama
   Inherits PhoneApplicationPage

   Public CurrentListEntradas As New List(Of ClaseAnimales_Entradas)
   Public Sub New()
        InitializeComponent()
        cargarListEntradas()
    End Sub

    Public Sub cargarListEntradas()
        Dim ae = From Animales_Entrada In db.Animales_Entrada Where Animales_Entrada.Eliminado = 0 Select Animales_Entrada.Fecha_entrada, Animales_Entrada.Numero

        For Each ele In ae
            CurrentListEntradas.Add(New ClaseAnimales_Entradas(ele.Fecha_entrada, ele.Numero))
        Next
        EntradasList.ItemsSource = CurrentListEntradas
    End Sub
End Class

What am I doing wrong? I don´t have errors but the listbox is empty.

Thanks in advance!!! Javi