0

我主要在ComboBoxes 和DataGrids 上进行数据绑定,并且我认为 a 的ListBox工作方式相同,但我似乎遗漏了一些东西,因为ListBox当我将 Scan 对象添加到我的可观察集合时,我仍然是空白的。知道我在这里缺少什么吗?

    <ListBox Height="480" HorizontalAlignment="Left" Margin="551,77,0,0" Name="ListBox_scans" VerticalAlignment="Top" Width="415" ItemsSource="{Binding}" >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Path=time}" />
                    <TextBlock Text="{Binding Path=station_name}"/>
                    <TextBlock Text="{Binding Path=Barcode}"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

扫描类:

Public Class Scan
Public Property Barcode As String
Public FromStation As Station
Public DateTimeUTC As DateTime
Public ScanType As String 'LotID, Employee Badge, Break, Complete, Duplicate
Public Duplicate As Boolean = False
Public IsWIPCleanUp As Boolean = False
Public IsComplete As Boolean = False

Public Property station_name As String
    Get
        If (Not FromStation Is Nothing) Then
            Return FromStation.Name
        Else
            Return "Station: No Station"
        End If
    End Get
    Set(value As String)

    End Set
End Property


Public Property time As String
    Get
        Return DateTimeUTC.ToLocalTime.ToShortTimeString()
    End Get
    Set(value As String)

    End Set
End Property

End Class

然后我只是在一些主代码中绑定:

Private scan_collection As New ObservableCollection(Of Scan)

ListBox_scans.ItemsSource = scan_collection
4

0 回答 0