In the XamFeatureBrowser, there's a sample that shows how to change the background of fixed fields.
Basically:
Normal 0 false false false EN-AU X-NONE X-NONE MicrosoftInternetExplorer4
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Style.Triggers>
<Trigger Property="IsFixed" Value="True">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Offset="0" Color="#00000000"/>
<GradientStop Offset="1" Color="#19000000"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
Now in the sample, for those fixed fields, the cells in the fixed fields are highlighted on mouse over and isSelected but when I copy the above XAML into my own grid, they no longer get highlighted.
Can anyone tell me what I'm missing here?
Hello,
The CellValuePresenter exposes several different properties for background - like Background, BackgroundSelected, BackgroundPrimary, BackgroundActive, BackgroundHover etc. controlling the different states of the Cells/Records. You should probably take into consideration them as well as the Background property.
None of these properties had any effect whatsoever on the cell in the fixed field. I also note that the sample didn't set any of these properties, as far as I could see.
The only way I could partially resolve it was to add triggers to my style and change the background back to transparent:
<DataTrigger Binding="{Binding Path=Record.IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="Background" Value="Transparent" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Record.IsActive, RelativeSource={RelativeSource Self}}" Value="True">
But there is no IsMouseOver property on the Record so I can't use the same logic to correct the highlight on mouse hover. Any ideas how I might go about that?
When I copy the styles from the xaml snippets of that sample in the XamFeatureBrowser, I get the exact same result. I am still not sure what you are trying to achieve. Do you want to get the same visual effect as the sample of you want to achieve something else?
If you want to get the same behavior, please note that the XamDataGrid is using a Theme - Office2kBlack. That is why you have to copy and paste the styles inside the XamDataGrid's Resources and nowhere else.
This post really helped. Thanks!
For anyone having a similar problem on setting CellValuePresenter, I was able to solve it by setting a trigger on IsMouseOverRecord and IsRecordSelected to set the Background to transparent.
<Style x:Key="myCell" TargetType="igDP:CellValuePresenter"> <Setter Property="Foreground" Value="Black" /> <Setter Property="Background" Value="LightCyan" /> <Style.Triggers> <Trigger Property="IsMouseOverRecord" Value="True"> <Setter Property="Background" Value="Transparent" /> </Trigger> <Trigger Property="IsRecordSelected" Value="True"> <Setter Property="Background" Value="Transparent" /> </Trigger> </Style.Triggers> </Style>
You can see in the attached image that when a row is selected (first highlighted record) or the mouse is hovering over it (second highlighted record), the cell in the fixed column is not highlighted. That is my problem.
Anyway, I found out what it was. Setting the Background property of the CellValuePresenter overlays the Record highlight on IsSelected or IsMouseOver. In the sample, the background is assigned a linear gradient brush which is mostly transparent, thus the record highlight shows through.
Unfortunately, I was assigning a background that was completely opaque which sat on top of (and therefore hid) the record highlight. So the solution is to set the CellValuePresenter Background property on IsFixed=true to be a semi-transparent colour.