I'm binding a XamDataGrid to a table that is created dynamically (AutoGenerateFields="True").
Each cell contains an object with info to know if the Foreground must be red or not
(number of columns can change but cells will always contains the same type of object).
So I was” thinking” to write a converter to change the foreground, however what I get is the DataItem,
and the DataItem is a DataRow and I don’t know how to get the value of “current” cell in the converter.
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Foreground"
Value="{Binding DataItem (I don’t know the cell),
Converter={StaticResource colorDiffenceItemConverter}}" />
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="True"
HighlightAlternateRecords="True" />
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:Field Name="Name" Label="{x:Static res:….}" />
<igDP:Field Name="AreEquals"
Label="AreEquals" Visibility="Collapsed"/>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
So, what I need to know is: In a table where the columns are created dynamically, How can I change the foreground of a cell based on a property of the object in the cell.
|Colum 0 | Colum 1| Colum 2| Colum 3| Colum 4|
|{1, true} |{1, true} |{1, False} |{1, true} |{1, False} |
So it should display
| 1 | 1 | 1 | 1 |1 |
Thanks,
Henry,
Hello Henry,
Thank you for your post. I have been looking into it and I suggest you use the following Setter instead of yours:
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Self}, Path=Value, Converter={StaticResource colorDiffenceItemConverter}}"/>
Using it you will have the current Cell’s Value as value in your converter. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Hi Stefan,
Thanks for your response.
So,
What I will get with this binding will be an Infragistics.Windows.DataPresenter.DataItemPresenter?
Because, I referred to {1, true} as an Object with two properties
So, I suppose that during the binding the Grid will call the ToString method of every object and will create a DataItemPresenter for each one. This is what I’m getting in the converter, there is no way what to get the object that was “binded” to the cell?
To give you a little more context: I have a Table that only contains objects of type A, every single A object has two properties a value and MustBeRed Boolean object. ToString method of A object will return the text to be displayed in the grid and I want to use MustBeRed to decide the color of the foreground using a converter, but with this binding I’m not getting the A object, I’m getting the string returned for ToString method.
If there is other way to achieve this goal that you can suggest, I’ll be happy to try.
thanks,
Henry Smith,
I have created a sample project for you with the functionality you want. Please let me know if this helps you or you need further assistance on this matter.
Hi,
Thanks for response,
In fact I did like you (the convertor) but taking a look in your example I saw that my issue was the type of the column in my dynamic table. I changed it and it's working as it should…
Thanks for your help!
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.