Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
CellValuePresenter Background binding
posted

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

Parents
  • 34810
    Offline posted

    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.

Reply Children