[英]what is the best way to bind ListView (WPF) with same icon for each item
I have a list view that is binded to some object I've created. 我有一个绑定到我创建的对象的列表视图。 The binding is working perfect, but I want to add icon to each item in my list. 绑定工作正常,但是我想向列表中的每个项目添加图标。 All the items should have the SAME icon (should be defined prior as "file.ico"). 所有项目均应具有SAME图标(应先定义为“ file.ico”)。 What is the best to implement this? 什么是最好的实现呢? Thanks. 谢谢。
Use an ItemTemplate , eg: 使用ItemTemplate ,例如:
<ListBox ItemsSource="{Binding MyItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="/Images/.." Width=".." Height=".." />
<TextBlock Grid.Column="1" Text="{Binding Name}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You should use a ListBox
unless you have a specific reason to use a ListView
. 除非有特殊原因要使用ListView
否则应使用ListBox
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.