【发布时间】:2015-01-20 01:51:45
【问题描述】:
假设我在我的视图模型中有一个人员列表:
public ObservableCollection<Person> Persons
Person 类是:
public class Person
{
public string Name{ get; set; }
public string Photo { get; set; }
}
我想在 ListView 中显示人员 到目前为止,一切都很好。 我有一组照片图像。 我的问题是:
- 我应该将这些照片作为资源添加到项目的“属性->资源”选项卡中还是将“构建操作”设置为“资源”的项目文件夹中?
- 如何将 Person Photo 属性绑定到相应的照片资源(假设照片图像名称与 Person Photo 属性相同)?
这是我的 XAML 代码,但绑定当然不起作用:
<ListView Grid.Column="0" Grid.Row="0" ItemsSource="{Binding Persons}" Margin="4">
<ListView.View>
<GridView ColumnHeaderToolTip="Persons Information">
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name"/>
<GridViewColumn Header="Photo" Width="60">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Photo}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
提前致谢。
【问题讨论】:
-
有什么建议吗?
-
那么,这不可能吗?
-
过几天我会修复你的:-)
-
对不起,我没听懂。
标签: wpf image listview binding resources