我将项目添加到了ListView中,并且这些元素都在其中。我知道这是因为我只能单击ListView的前两行,并且添加了2个Elements。
<ListView x:Name="userListview" HorizontalAlignment="Left" Height="220" Margin="40,40,0,0" VerticalAlignment="Top" Width="200">
<ListView.View>
<GridView AllowsColumnReorder="True" ColumnHeaderToolTip="User Informationen">
<GridViewColumn Header="User" Width="50" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="Email" Width="150" DisplayMemberBinding="{Binding Name}"/>
</GridView>
</ListView.View>
</ListView>
和我的VB.Net代码:
users = New ObservableCollection(Of UserInformation)()
For i = 0 To globalUserList.Count - 1
users.Add(New UserInformation() With {
.Username = globalUserList(i).ToString,
.Email = globalUserList(i + 1).ToString})
i = i + 1
Next
userListview.ItemsSource = users
预期结果应是这些项目可见且可读。
答案 0 :(得分:0)
您正在绑定属性Name
,该属性似乎不存在。
看起来应该是:
<GridViewColumn Header="User" Width="50" DisplayMemberBinding="{Binding Username}"/>
<GridViewColumn Header="Email" Width="150" DisplayMemberBinding="{Binding Email}"/>
答案 1 :(得分:0)
它应该看起来像这样。名称有误
<ListView x:Name="userListview" HorizontalAlignment="Left" Height="220" Margin="40,40,0,0" VerticalAlignment="Top" Width="200">
<ListView.View>
<GridView AllowsColumnReorder="True" ColumnHeaderToolTip="User Informationen">
<GridViewColumn Header="User" Width="50" DisplayMemberBinding="{Binding Username}"/>
<GridViewColumn Header="Email" Width="150" DisplayMemberBinding="{Binding Email}"/>
</GridView>
</ListView.View>
</ListView>