Hi All,
Can someone please help me. I need to change my Cell Background color, The user can select a color with a color picker that gets stored in configuration.
public SolidColorBrush SolidColorBrushValue { get { return MatrixView.SolidColorBrushValue; } set { if (MatrixView.SolidColorBrushValue!= value) { MatrixView.SolidColorBrushValue= value; RaisePropertyChanged("SolidColorBrushValue"); } } }
<Style x:Key="CellLockedStyle" TargetType="{x:Type igWPF:CellValuePresenter}"> <Setter Property="Background" Value="{Binding SolidColorBrushValue}"></Setter> <Setter Property="IsEnabled" Value="True"></Setter> <Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" /> </Style>
The color does not change when the property is triggered.
Thanks in advance,
Roelof
Hello Roelof,
It appears from the code that you have provided that you are trying to bind the Background property of the CellValuePresenter directly to your SolidColorBrushValue property, which I presume is on your underlying data item. This will not work, as the data context of the CellValuePresenter is the DataRecord that holds the cell that is being presented. This DataRecord has a DataItem property, though, which can be used to get your underlying data item and bind to the properties on it. As such, I would recommend reformatting your binding to look like the following:
<Setter Property="Background" Value="{Binding DataItem.SolidColorBrushValue}"></Setter>
It is also worth noting that you may be able to use a CellBinding to achieve your requirement in this case, rather than using a Style for CellValuePresenter. You can read about CellBindings in our online documentation, here.
Please let me know if you have any other questions or concerns on this matter.
HI Andrew,
Sorry for taking so long to get back to you. I've tried to implement the change but it does not seem to work. I've attached an example project.
If you could assist it would be appreciated.
0728.NewGridTest.zip
Thanks,
I have taken a look at the sample project that you have provided, and it appears that this isn't working as your bindings in your CellValuePresenter and DataRecordCellArea styles are not correct. It is also worth noting that at the moment, the CellValuePresenter style is attempting to be bound to the SolidColorBrushValue.Color property. This will never work, as the Background property expects a Brush derivation, and this will return a Color.
Looking at the structure of your sample project, it appears I was originally misguided in my impression that the SolidColorBrushValue property existed on the data item. It appears instead, that this exists on your "Application" class that serves as the data context of your grid. As such, I would recommend modifying your binding to point at:
<Setter Property="Background" Value="{Binding DataPresenter.DataContext.SolidColorBrushValue}">
Following the above binding path, the DataContext of the DataRecordCellArea and the CellValuePresenter is the same - it is the DataRecord that they represent or are a part of. This DataRecord has a DataPresenter property that binds up to the owning XamDataGrid. The DataContext of the XamDataGrid in this case is your "Application" object, which contains your SolidColorBrushValue property.
I have attached a modified version of the sample project you sent to demonstrate the above. I hope this helps you.
4274.NewGridTest.zip
Hi Andrew,
It works 100%. Thanks for the assistance.
Regards,