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.

  • 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>

  • 69686
    posted

    Hello,

    Please take a look at the following thread:

    http://forums.infragistics.com/forums/p/25409/93305.aspx#93305

    I believe it is the same issue. I would also suggest creating a style for the ValueEditor and setting the IsEnabled property of the editor, rather than the CellValuePresenter.

    Let me know if you need any more assistance or have questions on this matter.

    Regards,

    Alex.