I'm almost there, but not completely :
i have a listview binded to an observablecollection. I want the UI updated after i change the collection, and it does not work now. basically i have a listview and a button. After pressing the button a new item is added to the collection, but the UI stays the same. can someone points me to the right direction ?
thanks.
XAML :
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:StructureItems.SList"
x:Class="MainWindow"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Window.Resources>
<c:ItemList x:Key="SList"/>
</Window.Resources>
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="274,17,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<ListView Name="LV" HorizontalAlignment="Left" Height="300" Margin="10,10,0,0" VerticalAlignment="Top" Width="229" ItemsSource="{StaticResource SList}">
<ListView.View>
<GridView>
<GridViewColumn Header="Code" DisplayMemberBinding="{Binding Code}" Width="50"/>
<GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
Classes
Namespace SList
Public Class ItemList
Inherits ObservableCollection(Of StructureItem)
Public Sub New()
MyBase.Add(New StructureItem("A01", "Arcade"))
MyBase.Add(New StructureItem("A02", "Autentica"))
MyBase.Add(New StructureItem("A03", "Belface"))
MyBase.Add(New StructureItem("A04", "Heering"))
End Sub
Public Overloads Sub Add(code As String, description As String)
MyBase.Add(New StructureItem(code, description))
End Sub
End Class
Public Class StructureItem
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private _code As String
Private _description As String
Public Sub New(ByVal first As String, ByVal last As String)
Me._code = first
Me._description = last
End Sub
Public Property Code() As String
Get
Return Me._code
End Get
Set(ByVal value As String)
Me._code = value
OnPropertyChanged("Code")
End Set
End Property
Public Property Description() As String
Get
Return Me._description
End Get
Set(ByVal value As String)
Me._description = value
OnPropertyChanged("Description")
End Set
End Property
Protected Sub OnPropertyChanged(ByVal name As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
End Sub
End Class
End Namespace
code behind
Imports StructureItems.SList
Class MainWindow
Dim _item As New ItemList
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
_item.Add("A05", "Updated_")
End Sub
End Class