I am using a DataTrigger to set the background property of the CellValuePresenter. The converter sets the background color based on value in Field1Dummy as shown below...
<DataTrigger Binding="{Binding Path=Field.Name, RelativeSource={RelativeSource Self}}" Value="Field1"> <Setter Property="Background" Value="{Binding Path=Cells[Field1Dummy].Value, Converter={StaticResource myconv}}"/> </DataTrigger>
The above logic works fine. I have also set property SelectionTypeCell to Range. However, when I select a range a cells, the cell borders change color but background remains white. In other xamDataGrids that I have used, all the cells that are selected turn skyblue in color. I guess, the above DataTrigger the above DataTrigger might be conflicting with the background of selected cells.
I have tried:
<Setter Property="BackgroundSelected" Value="DarkBlue"/>
but the above doesn't seem to have any impact. Basically, I just want the selected range of cells to have color DarkBlue (or even the default is fine). How do I do this?
Thanks.
Hello Jay,
The development issue logged was resolved and concluded to be not a bug.
The issue is happening because in our ControlTemplate we have an element that is bound to the templated parent's Background property and it also has a (templater) trigger to set the Background property of the templated parent (namely the CVP) to the SelectedBackground. Because implicit style triggers have a higher precedence than control template triggers, as seen by your demo, the Background property was not changing.
To fix this I would consider changing the control template trigger such that instead of the setter setting the Background DP to the state based DP (like SelectedBackground), it would have to be changed to target the element in the template and instead change what property it was bound to.
Here are the following workarounds.
(a) Add another trigger that sets the Background to the brush they want when its selected:
<MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Path=Field.Name, RelativeSource={RelativeSource Self}}" Value="name" /> <Condition Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Self}}" Value="true" /> </MultiDataTrigger.Conditions> <Setter Property="Background" Value="{Binding BackgroundSelected, RelativeSource={RelativeSource Self}}"/> </MultiDataTrigger>
-OR-
(b) Remove the style trigger and instead set the FieldSettings->CellValuePresenterStyle of that specific field (since style triggers have a lower precedence than the template triggers):
<Window.Resources> <Style x:Key="nameCvpStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Background" Value="LightBlue"/> <Setter Property="BackgroundActive" Value="LightGreen" /> <Setter Property="BackgroundSelected" Value="LightGreen" /> <Setter Property="BorderThickness" Value="0,0,1,1" /> <Setter Property="BorderBrush" Value="LightGray" /> </Style> </Window.Resources> <Grid> <igDP:XamDataGrid BindToSampleData="True" Margin="50" Name="xamDataPresenter1" > <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings CellClickAction="SelectCell"/> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="True" SelectionTypeCell="Range"></igDP:FieldLayoutSettings> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:Field Name="name"> <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource nameCvpStyle}" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid>[/code]
Of those I would recommend (b) because you will not have to worry about which property the Background should be using at the time.
Let me know if you have any questions.
I am glad my work around has helped you. I have created case for you with ID CAS-182642-M9C8C9. You could reach your case following the link bellow:
https://ko.infragistics.com/my-account/support-activity I will update you via the mentioned case, so if you have any further questions or comments please update your case.
Hi Michael,
Your suggestion of using a second trigger based on IsSelected works perfectly - I am all set. Thanks.
Thank you for your reply. The selected background should be updating as expected as long as you are setting the BackgroundSelected for CellValuePresenter. I've discussed this with my team and have decided to investigate this further. I will be following up shortly after I report an official development issue. As a work around, you can add a second trigger based on the IsSelected property and change the Background according to the BackgroundSelected property.
eg.
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=Field.Name, RelativeSource={RelativeSource Self}}" Value="name"> <Setter Property="Background" Value="LightBlue"/> </DataTrigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{Binding Path=BackgroundSelected, RelativeSource={RelativeSource Self}}"/> </Trigger> </Style.Triggers> <Setter Property="BackgroundActive" Value="LightGreen" /> <Setter Property="BackgroundSelected" Value="LightGreen" /> </Style>
Dear Michael,
Thanks for the sample. In your sample, if I uncomment the DataTrigger, the highlighting of selected cells do not work. Note that I have set Value = "name" below....please try it.
<Style.Triggers> <DataTrigger Binding="{Binding Path=Field.Name, RelativeSource={RelativeSource Self}}" Value="name"> <Setter Property="Background" Value="LightGray"/> </DataTrigger> </Style.Triggers>
Note: In my actual application, I use a converter in the above DataTrigger and hence do need it. I guess, I need the BackgroundSelected property to override the Background property of CellValuePresenter - any workaround is fine too.