我有下面的listview,但是它没有显示实际的记录,而只显示了对象的名称空间。我想知道是否需要在XAML中创建列来显示记录,然后将其绑定到对象的某些属性,或者这样做有什么问题?
<ListView
Name="ListCustomers"
ItemsSource="{Binding Path=ListOfCustomers}"
SelectedItem="{Binding Path=SelectedCustomer}"
SelectionMode="Single"
IsSynchronizedWithCurrentItem="True"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
MinHeight="100"
></ListView>ListOfCustomers是一种ObservableCollection<Customer>类型。实际的客户会加载到ObservableCollection中,但不会显示。遗漏了什么?
发布于 2010-02-08 20:55:51
您还需要选择要显示的列:
<ListView ItemsSource="{Binding ListOfCustomers}"
SelectedItem="{Binding Path=SelectedCustomer}"
....>
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="First Name"
DisplayMemberBinding="{Binding FirstName}" />
<GridViewColumn Width="140" Header="Last Name"
DisplayMemberBinding="{Binding LastName}" />
<GridViewColumn Width="140" Header="Email Address"
DisplayMemberBinding="{Binding Email}" />
....
</GridView>
</ListView.View>
</ListView>发布于 2010-02-08 20:59:35
您也可以尝试
<ListView
.
.
ItemTemplate="{StaticResource CustomerDataTemplate}"
.
.
/>其中CustomerDataTemplate是Customer类的DataTemplate ...
发布于 2010-02-08 20:53:47
是否因为您尚未使用公开ListOfCustomers属性(返回要显示的项的列表)的实例设置ListView的DataContext属性?
https://stackoverflow.com/questions/2221621
复制相似问题