1
我的DataGrid中的XAML代码:添加项目到列表中DataGrid不显示
<DataGrid ItemsSource="{Binding Path=VoSamArtList}" Grid.Row="1" Margin="5,10,5,5" Grid.ColumnSpan="2"/>
我的按钮将项目添加到列表中的XAML:
<Button Grid.Row="2" Click="Button_Click"/>
我在VB代码属性:
Private _oVoSamArtLijst As New List(Of Product)
Public Property VoSamArtLijst As List(Of Product)
Get
Return _oVoSamArtLijst
End Get
Set(ByVal value As List(Of Product))
_oVoSamArtLijst = value
RaisePropertyChanged()
End Set
End Property
我的按钮单击VB代码:
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
VoSamArtList.Add(New Product("Id", "Length", "Width", "Height", "Code", "Quality", "Description", "Price"))
End Sub
我在我的项目中有几个其他Properties
更新,就像他们必须从TextBoxes
到Labels
一样测试Binding
。但将此List
与DataGrid
绑定似乎是一个困难的问题。如果我运行该程序,将生成列并使用Artikel Class
具有正确的名称。
我可能忘记了必须用Binding
List Of
's来完成的事情。当项目被添加或移除
所以我现在有'公共VoSamArtLijst作为新的ObservableCollection(产品)',并添加'RaisePropertyChanged( “VoSamArtLijst”)'我'Button_Click'事件,这可能并不完美但没有发生。 – Krowi
你在哪里有'公共VoSamArtLijst作为新的ObservableCollection(Of Product)'? – Paparazzi
这是我成为一个noob ...我以为我只需要'公共VoSamArtLijst作为新的ObservableCollection(Of Product)',但不是。再次添加我的属性,就像你在C#中的例子(我知道C#所以没问题;))。像现在的魅力一样工作,TNX。 – Krowi