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
120
Locking a cell and changing the background colour dynamically
posted

Given a collection of the following type:

public class Entity
{
    public string Name { get; set; }
    public bool IsLocked { get; set; }
}

I would like to lock (i.e. AllowEdit = false) and change the cell background of the Name field. I got it sort of working with the following XAML:

<ig:Field Name="Name" Label="Name">
    <ig:Field.Settings>
        <ig:FieldSettings>
            <ig:FieldSettings.CellValuePresenterStyle>
                <Style TargetType="ig:CellValuePresenter">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Record.DataItem.IsLocked, RelativeSource={RelativeSource Self}}" Value="True">
                            <DataTrigger.Setters>
                                <Setter Property="IsEnabled" Value="False" />
                                <Setter Property="Background" Value="Gray" />
                            </DataTrigger.Setters>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ig:FieldSettings.CellValuePresenterStyle>
        </ig:FieldSettings>
    </ig:Field.Settings>
</ig:Field>

But this only changes the colour of the cell's border, not the cell's background. Is there a way to achieve this using a DataTrigger? Preferably manipulating the AllowEdit on the FieldSettings.

Parents
No Data
Reply
  • 120
    Verified Answer
    posted

    Thanks! That solved my problem. For reference, this is what I ended up doing:

    <ig:Field Name="Name" Label="Name">
        <ig:Field.Settings>
            <ig:FieldSettings>
                <ig:FieldSettings.EditorStyle>
                    <Style TargetType="igEdit:ValueEditor">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding DataContext.DataItem.IsLocked, RelativeSource={RelativeSource Self}}" Value="True">
                                <DataTrigger.Setters>
                                    <Setter Property="IsReadOnly" Value="True" />
                                    <Setter Property="Background" Value="Gray" />
                                </DataTrigger.Setters>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ig:FieldSettings.EditorStyle>
            </ig:FieldSettings>
        </ig:Field.Settings>
    </ig:Field>

Children
No Data