已解决感谢Clemens。我只需要添加"属性"在" Public"之后的属性在我的班级定义中:
在VB.NET中,我试图让一个非常简单的Datagrid示例工作(即没有数据库连接的示例等)。但无论我尝试什么,Datagrid始终显示正确的行数和列的更正数(以及正确的列标题),但单元格为空:
Public Class GeneratedImage
Public Property AssignmentId As Integer
Public Property DocumentPageNumber As Integer
Public Property FullPathToImage As String
Public Sub New(id As Integer, pg As Integer, docpath As String)
AssignmentId = id
DocumentPageNumber = pg
FullPathToImage = docpath
End Sub
End Class
Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim myList As New List(Of GeneratedImage)
myList.Add(New GeneratedImage(1, 1, "c:\nowhere"))
myList.Add(New GeneratedImage(2, 2, "c:\nowhere2"))
GeneratedImagesInformationDatagrid.ItemsSource = myList
' GeneratedImagesInformationDatagrid.DataContext = myList
end sub
然后,在XAML中,我绑定如下:
<DataGrid x:Name="GeneratedImagesInformationDatagrid"
Height="500"
VerticalAlignment="Top"
ItemsSource="{Binding}"
Width="300">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=DocumentPageNumber}"
Header="Pg" />
<DataGridTextColumn Binding="{Binding Path=AssignmentId}"
Header="Assignment Id" />
<DataGridTextColumn Binding="{Binding Path=FullPathToImage}"
Header="Full Path To Image" />
</DataGrid.Columns>
</DataGrid>
我已尝试使用&#34; ItemsSource =&#34; {Binding}&#34;场。
任何帮助表示赞赏!
答案 0 :(得分:1)
已解决感谢Clemens。我只需要在我的类定义中的“Public”一词之后添加“Property”属性:
Public Class GeneratedImage
Public Property AssignmentId As Integer
Public Property DocumentPageNumber As Integer
Public Property FullPathToImage As String
.
. etc
等...