
I could derive from GridViewCell and put in my own behavior, since OnColumnChanged is protected, but the problem then becomes how to get the grid to use that cell instead of GridViewCell. I see that the only place GridViewCell is being created is in GridViewRow.CreateItem, which is an internal method and hence cannot be overriden by me. This leaves me no way of getting my CustomGridViewCell to be used in lieu of the default one.
Do you have any ideas of how I can deal with this issue?
Thanks
7 Answers, 1 is accepted
Basically, the virtualization of the RadGridView is turned on by default. Consequently, the visual elements are re-used when scrolling vertically and horizontally, which may lead to a result similar to the one you experience. However, this behavior depends on the way you are setting the particular properties - the Foreground in your case.
I am sending you the sample project I used for recreating your scenario. Please take a look at it and let me know in case there is some misunderstandings according to your requirements.
Regards,
Maya
the Telerik team

However, if I specify a CellTemplate which has a TextBlock inside of it with its Foreground set, sometimes the grid will reset the Foreground, based on the code in GridViewCell. Is there a reason why a CellStyle is preferred vs. a local Foreground setter on the TextBlock itself?
Basically, the CellStyle is defined on the GridViewCell level. Once you set a CellTemplate, whose element's properties contradict with those of the CellStyle (in your case Foreground property), the value set in the CellTemplate will be respected.
I have tested the issue you specified - that the CellStyle is sometimes applied and the Foreground of the TextBlock is not evaluated. However, I have not managed to reproduce the described behavior. Did you reproduce it in the sample project I attached previously ?
Maya
the Telerik team

<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Foreground="HotPink" />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
2) Start up the application
3) Position the mouse on the right border of the window so you see the horizontal resize grip ( looks like <--> )
4) Start resizing the window quickly, back and forth, so that you're occluding (i.e. hiding) the name column and showing it again.
5) Observe that not only the binding but the color of the cells changes.
The behavior you are getting is due to the enabled-by-default virtualization, i.e. the visual elements are reused on scrolling/ resizing. However, we are in the process of improving this functionality so that you do not experience such a behavior.
For the time being I would definitely recommend you to use the approach of setting a style for the GridViewCell. Another possible way (in case you do not work with lots of columns) is to disable the horizontal virtualization (EnableColumnVirtualization = "False").
Maya
the Telerik team

As a user I need to have a way to opt of out of this behavior. If I could supply my own GridViewCell which did not exhibit this behavior then that would be fine. But I can't because the GridViewRow method which creates GridViewCells is internal. Alternatively, if there was a switch to enable this behavior ONLY for TextBlocks but NOT for any class derived from TextBlock, that would help as well.
The point is that the grid is making an assumption that the GridViewCell Foreground clearing behavior is desirable for ALL TextBlocks, and that clearly is not the case here.
I hope a bug was opened for this issue.
Thanks
Indeed, you are quite correct - the behavior you are getting is not the desired one. We do make effort in the direction of improving our virtualization and the fixes will be available in some of our next internal builds.
For the time being I would recommend you to define a CellStyle for your columns. In case that does not meet your requirements, you may define your own custom column type as described in our online documentation and this blog post.
Let me know if you need any further assistance.
Maya
the Telerik team