This is a migrated thread and some comments may be shown as answers.

Change cell background for IsReadOnlyBinding = false

3 Answers 207 Views
GridView
This is a migrated thread and some comments may be shown as answers.
EAGLE
Top achievements
Rank 1
EAGLE asked on 21 May 2020, 04:04 PM

I use the IsReadOnlyBinding feature in some areas in GridView

Sample :  

IsReadOnlyBinding="{Binding AvgRateReadOnly}"

How can I change the background color for this  cells?(IsReadOnly Binding feature is false)

I can change cell background for Edit mode, but I want the change background color to look like the edit mode before  enter edit mode

How is possible?

Thanks

 

3 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 26 May 2020, 08:28 AM

Hello,

Thank you for the shared code snippet. 

In order to achieve the desired behavior, you can create a Style targeting GridViewCell and add a trigger:

<Style TargetType="telerik:GridViewCell">
            <Style.Triggers>
                <DataTrigger Binding="{Binding AvgRateReadOnly}" Value="False" >
                    <Setter Property="Background" Value="Red" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

If you want to apply this style only for certain columns, you can set the CellStyle property of the column to the respective style. 

I hope you find this information helpful.

Regards,
Vladimir Stoyanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
EAGLE
Top achievements
Rank 1
answered on 26 May 2020, 02:14 PM

I created a custom style 

public  class CustomStyle : StyleSelector
    {
        public Style ReadOnlyStyleProperty { get; set; }
 
        public override Style SelectStyle(object item, DependencyObject container)
        {
            var col = (container as GridViewCellBase).Column as GridViewDataColumn;
          
            if (col != null)
            {
                return col.CanEdit(item) ? this.ReadOnlyStyleProperty : base.SelectStyle(item, container) ;
            }
             
            return base.SelectStyle(item, container);
        }
    }

 

And applied like this approach

<someStyle:SomeStyle x:Key="CustomStyle">
      <someStyle:SomeStyle.ReadOnlyStyleProperty>
          <Style TargetType="telerik:GridViewCell"  BasedOn="{StaticResource {x:Type telerik:GridViewCell}}">
               <Setter Property="Background"  Value="LightYellow" />
            </Style>
       </someStyle:SomeStyle.ReadOnlyStyleProperty>
  </someStyle:SomeStyle>
 
0
Vladimir Stoyanov
Telerik team
answered on 28 May 2020, 11:17 AM

Hi,

I am glad to hear that you were able to achieve what you were going for. 

Thank you for sharing your approach with the community.

Regards,
Vladimir Stoyanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
GridView
Asked by
EAGLE
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
EAGLE
Top achievements
Rank 1
Share this question
or