Image from object in Datagrid template column

890 Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

The object type you should be exposing in your model should be one that derives from ImageSource such as BitmapImage.

The Image class is the element that displays an ImageSource, you can't assign an instance of Image to the Source property of another Image.