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

How to access ItemsControl from StyleSelector class

2 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vic
Top achievements
Rank 1
Iron
Vic asked on 13 May 2012, 09:41 PM
I'm testing out the RadGridView as a replacement for the standard wpf gridview I had been using.  I've got a complex row styleselector class which builds a style dynamically based on multiple criteria. I find that using the RadGridView I am no longer able to access the ItemsControl using ItemsControl.ItemsControlFromItemContainer(container) from within this class as it returns null.  I was using ItemsControl to determine is this was the first row in the collection.  Is there another alternative for identifying the first row in the collection from a styleselector?

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Ivanov
Telerik team
answered on 14 May 2012, 08:54 AM
Hello,

I would advise you to expose the data that would be used for conditional style selection through your business object, so that no access to visual objects should be needed. However, if you decide to stick to your former approach you can easily access the RadGridView instance like this:
public override Style SelectStyle(object item, DependencyObject container)
        {
            RadGridView radGridView = (container as GridViewRow).ParentOfType<RadGridView>();
  
            . . .
  
        }


Regards,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Vic
Top achievements
Rank 1
Iron
answered on 14 May 2012, 02:59 PM
Thanks for the advice Ivan.  You got me thinking in a new direction.  When building the object collection I will use a derived type for the first item that I can easily test for in the styleselector without increasing my memory footprint.
Tags
GridView
Asked by
Vic
Top achievements
Rank 1
Iron
Answers by
Ivan Ivanov
Telerik team
Vic
Top achievements
Rank 1
Iron
Share this question
or