DataGrid 是这样声明的
<DataGrid x:Name="DgDirectories"
AutoGenerateColumns="True" />
它是使用 DgDirectories.ItemSource
属性和我的 DTO 对象的 IEnumerable
动态填充的。此对象包含带有动态 图像的 byte[] 属性(HDD 上不存在)。
我想在网格中显示那些图像。
我尝试将 byte[]
转换为 BitmapImage
并将其与数据一起传递,但无论如何网格都会为这些类型创建 DataGridTextColumn
。
可能这可以更容易地完成,但我使用 WPF 的经验很少...... 请帮我在列中显示图像
P.S.:我是 WPF 的新手。
最佳答案
动态路径名绑定(bind)的Xaml代码
<DataGrid x:Name="dataGrid1" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding ImageFilePath}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
现在只需使用使用 IEnumerable 文件路径列表实例化的 uri 对象开始你的代码背后的逻辑...... 希望这就足够了
关于c# - 在 WPF Datagrid 中将动态图像设置为自动生成的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15603314/