Your code is listbox, so I tested the listbox binding. You could refer to the following code.
<Window x:Class="MainWindow"
xmlns:self="clr-namespace:DataBindindDeml"
mc:Ignorable="d"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Title="MainWindow" Height="450" Width="800">
<Window.DataContext>
<self:ListsVM />
</Window.DataContext>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadMe}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox
ItemsSource="{Binding SECategories}"
Margin="20" Width="300" Height="300"
SelectedItem="{Binding Path=CurrentSECategory}" >
</ListBox>
</Window>
Codebehind:
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports GalaSoft.MvvmLight.Command
Class MainWindow
End Class
Public Class ListsVM
Implements INotifyPropertyChanged
Private ReadOnly Property clsLoadMe As New RelayCommand(AddressOf PerformLoadMe)
Public ReadOnly Property LoadMe As RelayCommand
Get
Return clsLoadMe
End Get
End Property
Private Sub PerformLoadMe()
clsSECategories.Add(New SECategory() With {
.CategoryID = 1,
.Plural = "user1"
})
clsSECategories.Add(New SECategory() With {
.CategoryID = 2,
.Plural = "user2"
})
clsSECategories.Add(New SECategory() With {
.CategoryID = 3,
.Plural = "user3"
})
clsSECategories.Add(New SECategory() With {
.CategoryID = 5,
.Plural = "user4"
})
End Sub
Private clsSECategories As ObservableCollection(Of SECategory) = New ObservableCollection(Of SECategory)()
Public Property SECategories As ObservableCollection(Of SECategory)
Get
Return clsSECategories
End Get
Set(ByVal value As ObservableCollection(Of SECategory))
clsSECategories = value
NotifyPropertyChanged("SECategories")
End Set
End Property
Public Property CurrentSECategory As SECategory
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
Public Class SECategory
Public Property CategoryID As Integer
Public Property Plural As String
Public Overrides Function ToString() As String
Return Plural
End Function
End Class
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.