I used ItemsControl bounded to the ItemsSource collection, and I arranged items using the ItemsWrapGrid control panel. But ItemsWrapGrid panel was placed inside the ItemsPanelTemplate, so I couldn't access that element in the code behind c#.
I have tried with VisualTreeHelper method to find the panel in a visualtree. and doesn't retrieves the element when using inside the items panel template.
<ItemsControl
x:Name="itemsControl"
ItemTemplate="{TemplateBinding ItemTemplate}"
ItemsSource="{TemplateBinding GalleryItemCollection}"
SelectedItem="{TemplateBinding SelectedItem}">
<itemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid x:Name="itemsWrapGrid"
ItemHeight="{Binding Path=ItemHeight}"
ItemWidth="{Binding Path=ItemWidth}"
MaximumRowsOrColumns="{Binding Path=MaximumColumnCount}"
Orientation="Horizontal" />
</ItemsPanelTemplate>
</itemsControl.ItemsPanel>
</itemsControl>
Can someone please help me how to access the itemswrapGrid code element behind c#?
You could add a
Loaded
event handler to theItemsWrapGrid
control and assign the sender to a member variable, and then you could access theItemsWrapGrid
control by the member variable.For example: