I'm having an issues setting background color for specific column. I also want to make all other colors override that color, i.e. active, selected, hover colors. I'm able to override some of them using triggers, but not everything.
Here is the sample of the code where hover color for record is not overridden:
<igWPF:XamDataGrid DataSource="{Binding PersonViewModels}">
<igWPF:XamDataGrid.Resources>
<Style TargetType="{x:Type igWPF:DataRecordCellArea}">
<Setter Property ="Background" Value="Yellow"/>
<Setter Property ="BackgroundActive" Value="Blue"/>
<Setter Property ="BackgroundHover" Value="SkyBlue"/>
</Style>
<Style x:Key="DefaultRow" TargetType="{x:Type igWPF:CellValuePresenter}">
<Setter Property="BackgroundSelected" Value="DarkBlue"/>
<Style TargetType="{x:Type igWPF:CellValuePresenter}" BasedOn="{StaticResource DefaultRow}"/>
<Style x:Key="BrownRow" TargetType="{x:Type igWPF:CellValuePresenter}" BasedOn="{StaticResource DefaultRow}">
<Setter Property="Background" Value="Brown"/>
<Setter Property="BackgroundHover" Value="Brown"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsActive}" Value="True">
<Setter Property="Background" Value="Blue"/>
</DataTrigger>
</Style.Triggers>
</igWPF:XamDataGrid.Resources>
<igWPF:XamDataGrid.FieldLayouts>
<igWPF:FieldLayout>
<igWPF:FieldLayout.Fields>
<igWPF:Field Name="FirstName" Label="First Name"/>
<igWPF:Field Name="LastName" Label="Last Name"/>
<igWPF:Field Name="Age" Label="Age">
<igWPF:Field.Settings>
<igWPF:FieldSettings CellValuePresenterStyle="{StaticResource BrownRow}" />
</igWPF:Field.Settings>
</igWPF:Field>
</igWPF:FieldLayout.Fields>
</igWPF:FieldLayout>
</igWPF:XamDataGrid.FieldLayouts>
<igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:FieldLayoutSettings AutoGenerateFields="False" SelectionTypeCell="Extended" SelectionTypeRecord="Single" SelectionTypeField="Single"/>
</igWPF:XamDataGrid.FieldLayoutSettings>
</igWPF:XamDataGrid>
I've tried different options, but still wasn't able to handle all cases properly. Could anybody help me with this?
Hello Andrei,
Thank you for your post!
I have been investigating this issue, and the behavior you are currently seeing is expected. The CellValuePresenter of the XamDataGrid is in a lower part of the visual tree than the DataRecordCellArea, and as such, WPF will draw it on top of the DataRecordCellArea.
I would recommend that to override this, that you continue with the DataTriggers approach. I have created a sample based on the styles you have provided, and it appears that you have the selection and activation styles working. For the hover color, I would recommend using a DataTrigger with a RelativeSource AncestorType binding to the DataRecordCellArea in which the CellValuePresenter sits. If you point the binding path to the IsMouseOver property of the DataRecordCellArea and point the Value of the DataTrigger to true, you can set the Background property of the CellValuePresenter to the color you are using for the BackgroundHover property of the DataRecordCellArea.
I have attached the sample project I have created to demonstrate the above.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hi Andrew,
Thank you for you reply. You solution looks Ok. Although there is a small issue related to the hover background appearance when you move mouse over multiple rows. For the case with the trigger and without the trigger it looks slightly different. Where for yellow cells the transition is smooth and with kind of "fade-in" effect. For brown cells the hover background doesn't have such effects.I've tried to mimic such behaviour with storyboard items, although I haven't succeed yet. Do you have any ideas how to make them looking the same?
Regards,Andrei
I have been investigating for a way to get the "fade" animations to work in the sample I had sent you, and I would recommend that instead of simply setting the Background color in the DataTrigger that binds to IsMouseOver, that you assign the EnterActions and ExitActions of the DataTrigger. Inside of these actions, you can place a Storyboard with a ColorAnimation that targets the Background.(SolidColorBrush.Color) property and animate to SkyBlue in the EnterAction and back to Brown in the ExitAction.
There does exist an issue with this though, in that if you only implement the above, you will receive an exception when you hover over the "BrownRow" cells. This exception is caused by a conflict in an IsMouseOver MultiTrigger in the default style of the CellValuePresenter, which binds the Background of the CellValuePresenter. I would recommend that you include the default style for CellValuePresenter in your application, give it a key, and track down this MultiTrigger. It has three conditions: IsMouseOver = True, IsSelected = False, and IsFieldSelected = False. In the Setters for this MultiTrigger, comment out the Background setter and have your "DefaultRow" CellValuePresenter style be BasedOn the default style that is now included.
I have attached an updated version of the sample I had originally sent you to demonstrate the above. For reference, the CellValuePresenter default style can commonly be found here: C:\Program Files (x86)\Infragistics\2015.1\WPF\DefaultStyles\DataPresenter\DataPresenterGeneric_Express.xaml.
Thanks for your solution. There are still some minor issue left, although I'll try to fix them myself.
Thanks for your response. If you need assistance for these minor issues that remain, please feel free to let me know and I will assist as best I can.