Hi, here's how I do it in XAML:
<Style TargetType="{x:Type igWPF:CellValuePresenter}" x:Key="colorCell"><Style.Triggers> <DataTrigger Binding="{Binding IsSelected}" Value="True"> <Setter Property="Background" Value="SkyBlue"/> </DataTrigger> </Style.Triggers> </Style>
However, I need to be ale to change the selector's colour dynamically. In the debugger, the trigger's data seems to be correctly set, but I don't see the effect in the grid.
DataTrigger dataTrigger = new DataTrigger();dataTrigger.Binding = new Binding("{Binding IsSelected}");dataTrigger.Value = "True";dataTrigger.Setters.Add(new Setter(CellValuePresenter.BackgroundProperty, Brushes.Red));cellStyle.Triggers.Add(dataTrigger);
Please let me know if I need to change my code to make it work or refresh the grid somehow.
Thank you,
Paul
Hi Paul,
Thank you for posting to Infragistics Community!
Before I give suggestions about programmatically adding a Style, targeting an element within the XamDataGrid, I would like to discuss the XAML style snippet you have shared. I am wondering what is the result of this style in your app, does it really affect the cell value presenters selected color, even when defined in the template? I am asking this, as testing it on my side, this style does not seem to achieve anything. Also, the title of this thread mentions styling the Record Selector, however, the provided style is not related to it, at least base on my understanding so far.
Can you please, specify what is the purpose of the style, namely wether it is to:
To illustrate all this, I am attaching a sample app demonstrating styles that achieve the scenarios of the selected cells and record. As you will see, the sample applies Red background for individual selected cells, Yellow background for a selected record, and an Orange background for cells of a selected record having field names either “Region” or “Coal”.
Please, take a look at it and let me know if they accurately demonstrate what you are trying to achieve. If that is the case, there should be no issue in creating the same styles programmatically, with the approach you have already attempted, only targeting the needed properties in this case. Just make sure not to forget adding the style to the grid’s Resources collection as well.
In case the sample does not really reflect your requirements, please, feel free to share more details, as well as modify it with the relevant code, so that I can give further suggestions. Thank you for your cooperation.
Best regards,Bozhidara PachilovaAssociate Software Developer
4428.XDGProgrammaticStyle.zip
Hi Bozhidara,
Thank you for your reply and for the sample application!
What I had to do was to set BackgroundSelected and BackgroundActive in the DataRecordCellArea style instead of using a trigger. My problem is resolved!
Regards,