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,
Thank you for contacting Infragistics. First I would make sure that CellClickAction is sett to SelectCell. This will enforce that cells can be selected instead of records (by default). Then you can style records and cells based on your requirement.
eg.
<Window.Resources> <Style TargetType="{x:Type igDP:DataRecordCellArea}">
<Setter Property="BackgroundSelected" Value="Red"/>
<Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path= Record.Cells[0].Value}" Value="John Smith"> <Setter Property="Background" Value="Orange" /> </DataTrigger> </Style.Triggers>
</Style>
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="BackgroundSelected" Value="DarkBlue"/> </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> </Grid></Window>
Let me know if you havea any questions.
I have attached a snippet - I am selecting a range of cells across two columns - the first column has a background set and the second does not. As you can see, in the first column only the cell border is highlighted but in the second column all selected cells are highlighted.
Can someone please help with this!
Thank you for your reply. I've attached a sample that demonstrates multiple columns with the same selected background color. Based on your code snippet I don't know what the trigger is for. Keep in mind that both the cellvaluepresenter and datarecordcellarea have hover and active backgrounds that you can either set to the same color or transparent to hide the default "skyblue" color you see.
Please see my attached sample as I've demonstrated that you can selected and cell, across any column and it will only show one color.
Let me know if you have any questions.
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.
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.
<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.