Hi,
I need to mark a specific field in the XamDataGrid with a color (to mark it as a required field), so I wrote the following style:
And I assign the style to the specific field.
The only thing I wanted to change is the background of this field when it's not active and not select. I would like the color of the cell in this field to be the same as other fields when it's selected/active/hovered over, but for some reason this is not the case.
So my questions are:
1. The only thing I specified in my "requiredFieldCell" style is the background color. Why are all other colors are effected by this change too?
2. Whay else should I specify in my "requiredFieldCell" style to acheive the functionality I'm looking for?
Alex, thank you for the reply, but I'd liek to clarify something.
Yes, I want my new style to apply to all CellValuePresenters in the specific field except for the AddNewRecord, so this is fine.
Now, what I'm trying to acheive is when the whole record is selected/active/hovered, I want the cell in the specific field to get the same color as the cells in other fields.
I managed to come up with this:
<Style x:Key="requiredFieldCell" TargetType="{x:Type igDP:CellValuePresenter }">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions><Condition Property="IsSelected" Value="False"/>
<Condition Property="IsActive" Value="False"/><Condition Property="IsMouseOver" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{StaticResource requiredFieldBrush}" />
</MultiTrigger>
<DataTrigger Binding="{Binding Path=IsAddRecord, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordPresenter}}}" Value="True">
<Setter Property="Background" Value="Transparent" /></DataTrigger>
<DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordPresenter}}}" Value="True">
</DataTrigger><DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordPresenter}}}" Value="True">
</DataTrigger>
</Style.Triggers></Style>
This is almost what I wanted. Just instead of writing "Transparent" I would like to refer to the color that the default CellValuePresenter has in this case.
Hello,
This style would apply to all the CellValuePresenters in that field, because of the binding expression. Currently you require the DataRecordPresenter(Record) to be any other except the Add New Record.
So, the background would change for all the records except the Add New Record. Is that the behavior you want to achieve or you want to change the background for only the selected record? If this is the case you have to change the binding expression from IsAddRecord-False to IsActive-True.
There are several brushes that the CellValuePresenter has - for example - background, backgroundactive, backgroundfieldselected, etc. You might want to take a look at them and modify your style in regard to the setter property.
Hope this helps.