Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 在datagrid中不显示向列表中添加项_Wpf_Vb.net_List_Xaml_Datagrid - Fatal编程技术网

Wpf 在datagrid中不显示向列表中添加项

Wpf 在datagrid中不显示向列表中添加项,wpf,vb.net,list,xaml,datagrid,Wpf,Vb.net,List,Xaml,Datagrid,我的xaml代码中的DataGrid: <DataGrid ItemsSource="{Binding Path=VoSamArtList}" Grid.Row="1" Margin="5,10,5,5" Grid.ColumnSpan="2"/> 并在vb代码中单击我的按钮: Private _oVoSamArtLijst As New List(Of Product) Public Property VoSamArtLijst As List(Of Product) G

我的xaml代码中的DataGrid:

<DataGrid ItemsSource="{Binding Path=VoSamArtList}" Grid.Row="1" Margin="5,10,5,5" Grid.ColumnSpan="2"/>
并在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
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    VoSamArtList.Add(New Product("Id", "Length", "Width", "Height", "Code", "Quality", "Description", "Price"))
End Sub
在我的项目中,我有几个其他属性可以更新,就像它们必须喜欢从文本框到标签的绑定测试一样。但是将这个列表绑定到DataGrid似乎是一件困难的事情。如果我运行该程序,将生成列并使用Artikel类中的正确名称


我可能忘记了必须对绑定列表执行的操作。

需要使用ObservableCollection

当添加或删除项时,ObservableCollection会发出通知

这可能并不完美,因为我使用C

Private _oVoSamArtLijst As New ObservableCollection(Of Product)
Public Property VoSamArtLijst As ObservableCollection(Of Product)
    Get
        Return _oVoSamArtLijst
    End Get
    Set(ByVal value As ObservableCollection(Of Product))
        _oVoSamArtLijst = value
        RaisePropertyChanged()
    End Set
End Property

需要使用ObservableCollection

当添加或删除项时,ObservableCollection会发出通知

这可能并不完美,因为我使用C

Private _oVoSamArtLijst As New ObservableCollection(Of Product)
Public Property VoSamArtLijst As ObservableCollection(Of Product)
    Get
        Return _oVoSamArtLijst
    End Get
    Set(ByVal value As ObservableCollection(Of Product))
        _oVoSamArtLijst = value
        RaisePropertyChanged()
    End Set
End Property

所以我现在有了“Public VoSamArtLijst As New ObservableCollectionOf Product”,并在我的按钮点击事件中添加了RaiseProperty ChangedVosamartLijst,但什么都没有发生。哪里有“Public VoSamArtLijst As New ObservableCollectionOf Product”?我是一个noob…我以为我只需要Public VoSamArtLijst As New ObservableCollectionOf Product产品,但不是。再次添加我的属性,就像您在C中的示例一样,我知道C,所以没问题。现在工作得很有魅力,tnx。UI只看到公共属性。你可能有一个隐式的私人演员。所以我现在有了“Public VoSamArtLijst As New ObservableCollectionOf Product”,并在我的Button_Click事件中添加了RaiseProperty ChangedVosamartlijst,但什么都没有发生。你在哪里有“Public VoSamArtLijst As New ObservableCollectionOf Product”?我是一个noob…我我想我只需要公开Vosamatlijst作为新的产品集合,但不需要。再次添加我的属性,就像您在C中的示例一样,我知道C,所以没问题。现在工作得很有魅力,tnx。UI只看到公共属性。你可能有一个隐晦的演员阵容。