Searched the forums but did not find a clear solution. I need a way to have an image and cell text to be displayed at the same time. I am able to display either in two separate columns. I have attempted to modify default CellValuePresenter style but its unclear how precisely the binding should be set. Assume I have the following structure in XAML:
<igDP:XamDataGrid>
<igDP:XamDataGrid.Resources><Style x:Key="imageStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </igDP:XamDataGrid.Resources>
<igDP:Field Name="Status"> <igDP:Field.Settings> <igDP:FieldSettings FilterLabelIconDropDownType="MultiSelectExcelStyle"/> </igDP:Field.Settings> </igDP:Field>
<igDP:Field Name="StatusImageURI" Label="Status"> <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource imageStyle}"/> </igDP:Field.Settings> </igDP:Field>
So columns for Status and StatusImageURI contain the text and the Image to be displayed. I suppose another way to do this would be to merge these two columns. Any solution is acceptable. Thanks.
Hello Andre,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
I created a sample project for you with the functionality you want. Basically I used a MultiBinding for the TextBlock's Text and in the Converter's Convert method a return different value based on the Field's Name. This way you can use the same template for multiple Fields. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Stefan, thats cleaner. Is there any way to set the text field dynamically? I am trying to reuse the same template for more than one cell and the column for text will be different. Thanks.
You can use this Path in the Binding instead of yours:
Record.DataItem.PropertyName
where "PropertyName" is the name of the Property, from your underlying object, which you want to show. Please let me know if you have further questions on this matter.
Thanks Stefan, I did see that sample yesterday but for some reason I did not like the usage of triggers there. Either way, I took another look and came up with the following template that works exactly how I like. The only thing I'm not sure is how I reference the Text column - Record.Cell[index].Value. Is there a cleaner way to retrieve this value so that the cell index isn't hardcoded in the template but set dynamically from within the Field definition? Thanks
<Style x:Key="ImageAndTextTemplate" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" Width="16" Height="16" Margin="5" /> <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}}, Path=Record.Cells[4].Value}"/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style>