Hi guys,
I am trying to display an image in a cell (UnboundField) of a XamDataGrid based on a value of another cell.
With a DataGrid I got it working like this:
<DataGrid Name="dataGrid" ItemsSource="{Binding}" > <DataGrid.Columns> <DataGridTemplateColumn Header="Text" Width="SizeToCells" IsReadOnly="True"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Image Source="{Binding Path=id, Converter={StaticResource IdToImageConverter}, ConverterParameter='png'}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns></DataGrid>
Could anyone help me with that in a XamDatagrid? This is my code which is not working, I guess the problem is the wrong RelativeSource in the ControlTemplate:
<UserControl.Resources> <local:IdToImageConverter x:Key="IdToImageConverter" /> <Style x:Key="IconCellStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Grid> <Image Source="{Binding Path=id, Converter={StaticResource IdToImageConverter}, ConverterParameter=png, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style></UserControl.Resources><igDP:XamDataGrid Name="xamDataGrid" DataSource="{Binding}" > <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:UnboundField Label="Text"> <igDP:UnboundField.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource IconCellStyle}" /> </igDP:UnboundField.Settings> </igDP:UnboundField> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts></igDP:XamDataGrid>
Thanks a lot and kindregards!
Hi Gawain,
Please see the following forum thread for filters with images. http://es.infragistics.com/community/forums/t/40977.aspx
For loading PDFs as images into the XamDataGrid, as long as you already have the images you can display them in the XamDataGrid as you would any other image. Converting PDF to an image though, is another matter. Currently Infragistics doesn't have the ability to take a PDF and generate images from it. There are a number of free options available though. Please see the following for one such option: http://stackoverflow.com/questions/22505502/convert-pdf-to-jpg-images-library-c-sharp-without-using-ghostscript
Thanks, this is perfectly workig. Two more question:
Regards!
You don't actually need a RelativeSource binding there. The datacontext of a CellValuePresenter is a DataRecord. Inside DataRecord there is a property called DataItem which represents your underyling row object. All you need is a binding to DataItem.id.