On the below style, I have the background set to Yellow, if there converter on the datatrigger passes true, the background is blue.
That all works fine. However, I set the BackgroundSelected to Green, and that also works fine, except for the cells which the converter is passing true, in which case it is stuck on blue when selected. How would I be able to set the backgroundselected to green when the datatrigger passes true?
<Style x:Key="SampleStyle" TargetType="{x:Type igWPF:CellValuePresenter}" >
<Setter Property="Background" Value="Yellow"/>
<Setter Property="BackgroundSelected" Value="Green"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Record.DataItem.CHN, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type igWPF:DataRecordCellArea}}, Converter={StaticResource SampleStyleConverter}}" Value="True">
<Setter Property="Background" Value="Blue"/>
</DataTrigger>
</Style.Triggers>
</Style>
Created a sample project to demonstrate the issue.
Hello Michael and thank you for posting!
Setting the Background property in a DataTrigger prevents the template triggers in the default CellValuePresenter template from working. You can modify the default template that is located at C:\Program Files (x86)\Infragistics\2014.1\WPF\DefaultStyles\DataPresenter\DataPresenterGeneric_Express.xaml or add MultiDataTrigger to set the Background property as so:<MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Path=Record.DataItem.Chain, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type igWPF:DataRecordCellArea}}, Converter={StaticResource Conv}}" Value="True"/> <Condition Binding="{Binding IsSelected}" Value="False"/> <Condition Binding="{Binding IsActive}" Value="False"/> </MultiDataTrigger.Conditions> <MultiDataTrigger.Setters> <Setter Property="Background" Value="Cyan"/> </MultiDataTrigger.Setters> </MultiDataTrigger> If you have further questions, do not hesitate to ask.
Thanks Maria,
I like the multi trigger option, however the example you provided impacts the record and not the individual cells, would you be able to point me the right way on that?
Something like:
<Condition Binding="{Binding Path=Record.DataItem.IsSelected, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type igWPF:DataRecordCellArea}}}" Value="True"/>
But I can't get that to work..
Hi Michael,
The DataItem property of the record returns the underlying object that is used to populate the record with data. This means that the Record.DataItem.Chain and Record.DataItem.IsSelected will be true for all the cells in the record so the condition will be met and the background will be set for all cells in that record. If you would like to set the background for each cell based on its value, binding the cell to its value using RelativeSource could be helpful. Here a code snippet for the same could be found: http://ko.infragistics.com/community/forums/t/91509.aspx.
Hi Maria, thank you, that isn't exactly what I was aiming for, as I do want to adjust the background based on the value but also if the cell itself (rather than the row) is selected. However, I found the answer:
<MultiDataTrigger.Conditions> <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.Chain, Converter={StaticResource Conv}}" Value="True"/> <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}" Value="True"/> </MultiDataTrigger.Conditions>
This will allow me to format the background based on the value of field Chain and if the cell is selected. Thanks for guidance in this issue!
I am glad you have this issue resolved on your side. Sharing the approach in the thread would help other community members as well. Thank you.