Alex Rivera | Logout

How to get instance of Panel that holds content of ItemsControl?

Asked 2011-01-20T07:55:08.457
32

Every ItemsControl has its content stored in Panel right ? We can specify the panel to be used in XAML like this:

<ListView Name="LView">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate >
            <StackPanel/>
        </ItemsPanelTemplate>
     </ListView.ItemsPanel>
</ListView>

My question is how to get instance of Panel that is used in the ItemsPanel property (of type ItemsPanelTemplate) of the particular ItemsControl ? For example ListView called LView from above code sample?

I cannot use Name property or x:Name, this must work for any ItemsControl even those using default ItemsPanel.

In the case its not clear please comment, I think there is very simple solution. If it seems to be complicated that's only because I cannot explain it properly.

Edit
Report

1 Answer

3

I can't provide you with working code, but have a look at VisualTreeHelper class. With the VisualTreeHelper class you can traverse the visual tree down to your template and panel.

answered 2011-01-20T08:25:14.140

Your Answer