gpt4 book ai didi

c# - 在 WPF Datagrid 中将动态图像设置为自动生成的列

转载 作者:太空宇宙 更新时间:2023-11-03 17:05:54 27 4
gpt4 key购买 nike

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com