[英]Can I bind a single property in an ObservableCollection to ListView in WPF?
My ViewModel contains an ObservableCollection<TDL>
. 我的ViewModel包含一个
ObservableCollection<TDL>
。
Each item is an instance of TDL: 每个项目都是TDL的一个实例:
public class TDL
{
public string DataFile { get; set; }
public List<Task> Items { get; set; }
public int Id { get; set; }
public string Name { get; set; }
}
I want all the names to be displayed in a ListView. 我希望所有名称都显示在ListView中。 Can I bind only the
Name
property? 我可以仅绑定
Name
属性吗?
ObservableCollection<TDL>
needs to be set as ItemSource
of ListView
. 需要将
ObservableCollection<TDL>
设置为ListView
ItemSource
。 Property You like to have as displayed one, needs to be defined in <ListView.View>
attribute, as presented below: 您想要显示的属性需要在
<ListView.View>
属性中定义,如下所示:
<ListView ItemsSource="{Binding NameOfObservableCollectionProperty}"....>
<ListView.View>
<GridView>
<GridViewColumn Header="Name"
DisplayMemberBinding="{Binding Name}" />
</GridView>
</ListView.View>
</ListView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.