There are many ways to do that.
- The easiest one is to wrap your
DataTemplate
contents into aUserControl
. - Another one is to use something like
ContainerFromIndex()
. - Then you can also use
VisualTreeHelper
class to walk the visual tree. - Then again you can subclass your
ItemsControl
and overrideGetContainerForItemOverride()
orPrepareContainerForItemOverride()
or - use the
ItemContainerGenerator
property
The imporant thing to note is that your ItemsSource
provides items to the control while the overrides or the generator provide containers to display the items using the ItemTemplates
.
*Edit As for your additional questions:
How to modify/access the "ItemTemplateSelector" and SelectionMode etc. of the GridView?
You have defined your selector resource and gave it a key of "textbookTemplateSelector", so you can just get it with this.Resources["textbookTemplateSelector"].SelectionMode
you can bind to the same sourceDataContext
you bound yourItemsSource
to and change or read it through a binding.Is there a way to access each of the items in the booksGridView?
Yes. Since yourDataContext
is set as theItemsSource
of yourListView
- you can access all the items through thatDataContext
. Each of these items seems to have anItems
property that is bound to yourGridView
, so you can access each of these through theItems
property you have defined yourself.