I have a dataset with a few int fields that need to display as images. The value for these fields is 1,2,3,4, or 5. Based on the value of that field I want to display one of five images in the cell.
Hello,
What you need to do is to retemplate the CellValuePresenter and put an Image element inside it.
You can assign this style to the specific field's CellValuePresenterStyle property of the FieldSettings.
In the control template, you can create DataTriggers to bind any cell's value to the source property of the image. For example, the following code snippet changes the image depending on the Id field of the XamDataGrid.
<Style x:Key="imageStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Image x:Name="image" Width="20" Height="20" Source="blue.png"/>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Cells[Id].Value}" Value="1">
<Setter TargetName="image" Property="Source" Value="blue.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Cells[Id].Value}" Value="2">
<Setter TargetName="image" Property="Source" Value="red.png"/>
<DataTrigger Binding="{Binding Path=Cells[Id].Value}" Value="3">
<Setter TargetName="image" Property="Source" Value="yellow.png"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Hope this helps.
Thanks for your help. I think I'm almost there. Is there a way inside of the template to see which column I'm currently working with. I have 3 or 4 columns that need this logic and I'm trying to see if I can use one template instead of creating a template for each data point that needs this logic.