来自 Datagrid 模板列中对象的图像
我试图在模板列中的数据网格中显示图像,代码:
<data:DataGridTemplateColumn Header="" x:Name="colPriority">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Border BorderBrush="Black" Background="{Binding TimeMarker.TimeMarkerBrush}" BorderThickness="1" Width="38" ToolTipService.ToolTip="{Binding Path=TimeMarker.TimeMarkerName, StringFormat='Priority: {0}'}">
<Image
Source="{Binding ImageFlag}"
ToolTipService.ToolTip="{Binding TaskFlagStatus}"
Height="32"
Width="32"
Margin="3"/>
</Border>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
“ImageFlag”是我的对象中“图像”类型的属性。问题是它没有显示出来。当我将 xaml 中的源更改为图像的相对 URI 时,它显示正常,但不会显示存储在对象的“ImageFlag”属性中的图像。为什么?
I am trying to display an image in my datagrid in a template column, the code:
<data:DataGridTemplateColumn Header="" x:Name="colPriority">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Border BorderBrush="Black" Background="{Binding TimeMarker.TimeMarkerBrush}" BorderThickness="1" Width="38" ToolTipService.ToolTip="{Binding Path=TimeMarker.TimeMarkerName, StringFormat='Priority: {0}'}">
<Image
Source="{Binding ImageFlag}"
ToolTipService.ToolTip="{Binding TaskFlagStatus}"
Height="32"
Width="32"
Margin="3"/>
</Border>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
'ImageFlag' is a property of type 'image' in my object. The problem is that it is not showing up. When I change the source in the xaml to the relative URI of an image it shows up fine, but it won't show the image that is stored in the 'ImageFlag' property of my object. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在模型中公开的对象类型应该是派生自
ImageSource
的对象类型,例如BitmapImage
。Image
类是显示ImageSource
的元素,您不能将Image
的实例分配给Source
> 另一个图像
的属性。The object type you should be exposing in your model should be one that derives from
ImageSource
such asBitmapImage
.The
Image
class is the element that displays anImageSource
, you can't assign an instance ofImage
to theSource
property of anotherImage
.