2

I'm using the MVVM pattern with Xceed's WPF DataGridControl and I've bound a column of my grid to a boolean property on my view-model/data-context.

By default it displays as a checkbox, instead I'd like to display an image e.g. a smile face for True and a sad face for False. It doesn't need to behave like a checkbox as the column is read-only.

What is the best way to achieve this?

chillitom
  • 24,888
  • 17
  • 83
  • 118

2 Answers2

1

There was a blog posted on Xceeds website about how to style a DataCell based on other values. So essentially, you can create a DataTemplate with an image control in it and you can create a condition where you set the happy face if the value is true and a sad face if the value is false. Here is the following link that shows how to do this:

http://xceed.com/CS/blogs/techside/archive/2011/07/06/datacell-styling-vs-cellcontenttemplate.aspx

Nerd in Training
  • 2,098
  • 1
  • 22
  • 44
0

you have to create data grid template column to achieve custom style.

    <DataGrid.Columns>
     <DataGridTemplateColumn Header="First Name" IsReadOnly="True" Width="Auto" MinWidth="100" CanUserSort="True">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
<Grid>
                                        <Image Source="smile.jpg"/>
                                        <Image Source="smile.jpg"/>
</Grid>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn> 

    </DataGrid.Columns>

you can further use datatriggers to play with visibility of images

Bathineni
  • 3,436
  • 18
  • 25