[英]WPF Listview binding to ItemSource?
我有以下列表视图,但它不显示实际记录,而只显示对象的命名空间。 我想知道是否需要在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中,但不会显示它们。 缺什么?
您还需要选择要显示的列:
<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>
你也可以试试
<ListView
.
.
ItemTemplate="{StaticResource CustomerDataTemplate}"
.
.
/>
CustomerDataTemplate是CustomerTemplate for Customer类的地方......
是因为您没有使用公开ListOfCustomers
属性的实例(返回要显示的项列表)设置ListView的DataContext
属性?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.