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

CellStyleSelector not being applied while scrolling

2 Answers 83 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Amara
Top achievements
Rank 1
Amara asked on 29 Oct 2010, 04:53 PM
Hi Telerik Team,

I am currently using CellStyleSelector feature of a GridViewDataColumn to apply selective styles.

But styles are not being applied properly to few cells in middle when the grid is scrolled.

We bound the columns to the grid using _grid.Columns.AddRange(columns);
Rows are also added to the grid using _grid.ItemSource(rows).

I am creating MyStyleSelector.cs in following way
public class MyStyleSelector : StyleSelector
   {
       private static readonly Brush DefaultBackgroundBrush = new SolidColorBrush(Colors.Brown);
       public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
       {
           var style = new Style(typeof(GridViewCell));
           var background = DefaultBackgroundBrush;
           style.Setters.Add(new Setter(GridViewCell.BackgroundProperty, background));
           return style;
       }
   }

and applying it to the gridcolumn
gridViewDataColumn.CellStyleSelector = App.Current.Resources["styleSelector"] as StyleSelector;

I am currently using RadControls version 2010.2.714.1030. and Silverlight 3. Moving to silverlight 4 is not an option currently.

Any help would be appreciated.

Thank you.

2 Answers, 1 is accepted

Sort by
0
Amara
Top achievements
Rank 1
answered on 02 Nov 2010, 03:06 PM
Hi Telerik team,

I have been able to reproduce the problem in a simple project. I am creating a support ticket for this issue and attaching the Project.

Thank you.
0
Maya
Telerik team
answered on 03 Nov 2010, 01:05 PM
Hello Julia POKHVALIEVA,

Looking at the code-snippet and the sample project you provided, I may suggest to you a couple of options that will achieve the same result, but without causing the undesired effect you are getting. Firstly, you may define an implicit style for the row and set its Background property (in case of Silverlight 3 you have to define the Key modifier of the style and then set it as the RowStyle):

<UserControl.Resources>
   <Style TargetType="telerik:GridViewRow">
    <Setter Property="Background" Value="Blue" />
   </Style>
</UserControl.Resources>
 
Silverlight 3:
<UserControl.Resources>
  <Style x:Key="RowStyle" TargetType="telerik:GridViewRow">
    <Setter Property="Background" Value="Blue" />
  </Style>
</UserControl.Resources>
 
<grid:RadGridView x:Name="_grid" RowStyle="{StaticResource RowStyle}" />

Another approach may be to set the Background property of the row during the RowLoaded event. Furthermore, if you do not support a lot of data, you may turn off the horizontal virtualization by using the EnableColumnVirtualization property of the grid.
 

Best wishes,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Amara
Top achievements
Rank 1
Answers by
Amara
Top achievements
Rank 1
Maya
Telerik team
Share this question
or