Hello all,
I have this style in my grid as follows:
<Style TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}" >
<Setter Property="Background" Value="{Binding ., Converter={StaticResource StateToBackgroundBrushValueConverter}}" >
</Style>
I am trying to bind to the actual cell that is being styled, but using the above approach, it gives me the Record that the cell belongs to instead, which strikes me as odd. How can I get hold of the cell?
Thanks
Hello,
This is because the DataContext of the CellValuePresenter is the DataRecord itself. What you could do is modify the binding so that the path property points to the Value and you need to set the RelativeSource to Self. Another way would be to set the path to DataItem.PropertyName or Cells[X].Value where X is either the index of the field or the name of the field.
Thanks.
What I'm aiming to do though is have my converter return a colour based on not only the data item, but also the field in which the cell lives under.
Is there anything I can bind to which would have a reference to both?
Edit: Looks like the CellValuePresenter does have references to both, can't test at the moment though.
Yes, the CVP has both Record and Field properties which you can use. Another way would be to use a MultiValueConverter which supports binding to multiple values.
Tried doing
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource StateToBackgroundBrushValueConverter}}" > </Setter>
In my converter I get passed the CellValuePresenter, but it seems to have nothing on it, so field etc is null.
{CellValuePresenter: DataRecord- -1 State: [null]} base {Infragistics.Windows.DataPresenter.DataItemPresenter}: {CellValuePresenter: DataRecord- -1 State: [null]}
Any ideas why this would be?
I would recommend going through this blog post and the sample included in case you haven't looked at it yet.
The converter could bring a null value in some cases. Does it return null every time the Convert method is called?
Yep null each time.
On a related note, is it possible to have the converter return a CellValuePresenter which can then be used?
So instead of binding all the properties to different values each with their own converter, I'd rather just define the CellValuePresenter in code and supply that back.