Hi,
I would like to apply color on my background records depending on the 'Type' cell value
example : The lines where the 'Type' cell value is 'Réunion' must have a red backround
Dim HT As New Hashtable() Query.GetHTColors(HT) ' Get the hashtable where each type is associated with a color Dim MyBrush As New SolidColorBrush() For Each Rec As Infragistics.Windows.DataPresenter.DataRecord In Me.XamDataGrid_CRA.Records If Not IsDBNull(HT(Rec.Cells("Type").Value)) Then MyBrush = New SolidColorBrush(CType(ColorConverter.ConvertFromString(HT(Rec.Cells("Type").Value)), Color)) Else MyBrush = Brushes.White End If '' '' How to apply MyBrush on the background ??? (here) '' Next
Dim HT As New Hashtable() Query.GetHTColors(HT) ' Get the hashtable where each type is associated with a color
Dim MyBrush As New SolidColorBrush()
For Each Rec As Infragistics.Windows.DataPresenter.DataRecord In Me.XamDataGrid_CRA.Records If Not IsDBNull(HT(Rec.Cells("Type").Value)) Then MyBrush = New SolidColorBrush(CType(ColorConverter.ConvertFromString(HT(Rec.Cells("Type").Value)), Color)) Else MyBrush = Brushes.White End If
''
'' How to apply MyBrush on the background ??? (here)
Next
I have tried everything ... HELP
Thanks
Becquet.Steve
Hello Steve,
I have been looking into your issue and can suggest using a Style with a DataTrigger like this one:
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Record.Cells[2].Value,RelativeSource={RelativeSource Mode=Self}}" Value="Réunion">
<Setter Property="Background" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
in order to get a consistent behavior.
Please let me know if you require any further assistance on the matter.
Sincerely,
Petar Monov
Developer Support Engineer
Infragistics Bulgaria
www.infragistics.com/support
Hi Petar,
Thanks for your fast answer !!
All my 'Type colors' are in the hashtable HT and may change, i can also add new types and change their colors (stored in a SQL DB).
So, i would like to apply the background programmatically with VB and not XAML ...
I saw a few things about DataPresenter.DataRecordPresenter.FromRecord(...).Background= ...
But I don't know how to integrate it in my code :(
up.
I see what you mean. What you can do is use a DynamicResource instead the static value, I have provided for the sample snippet, like so:
…
<Setter Property="Background" Value="{DynamicResource MyHashValue}"/>
And initially set it in code:
this.Resources.Add("MyHashValue", new SolidColorBrush(Colors.Red));
and switch it like so:
this.Resources.Remove("MyHashValue");
this.Resources.Add("MyHashValue", new SolidColorBrush(Colors.Aqua));
You can also reference this link: http://msdn.microsoft.com/en-us/library/ms750613.aspx to see if there is more suited approach for you.
Hope this helps.
Regards Petar.
I finally found, programmatically, how to access the datapresenter of a row without binding.
Like this :
For Each Rec In XamDataGrid_Adh.Records
Dim dp As Infragistics.Windows.DataPresenter.DataRecordPresenter = Infragistics.Windows.DataPresenter.DataRecordPresenter.FromRecord(Rec)
Dim MyBrush = [...] 'select the color with a converter
dp.Background = MyBrush
and use it in a refresh() function !