DataGrid 中的 WPF 图像绑定 [英] WPF Image bind in DataGrid
本文介绍了DataGrid 中的 WPF 图像绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在DataGrid中绑定图片?
How to bind an image in DataGrid?
<my:DataGrid.Columns>
<my:DataGridTemplateColumn Header="状況写真" Width="100">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image >
??????????????????
</Image>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
谢谢,维杰
推荐答案
Image 从 Source 属性中获取其值,因此您需要绑定它.这是 ItemsControl 的示例.
Image takes its value from the Source property so you need to bind this. Here is an example with ItemsControl.
<ItemsControl Name="imageList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- The Image binding -->
<Image Source="{Binding Path=Value}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我使用以下代码来初始化 imageList 的项目源.
I used the following code to initialize the items source for the imageList.
List<KeyValuePair<string, string>> images =
new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string,string>("Image1", @"D:Photos n-35.jpg"),
new KeyValuePair<string,string>("Image2", @"D:Photos n-36.jpg"),
new KeyValuePair<string,string>("Image3", @"D:Photos n-37.jpg")
};
imageList.ItemsSource = images;
这篇关于DataGrid 中的 WPF 图像绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文