tags:

views:

20

answers:

2

When I use a ListBox - the elements inside are of type ListBoxItem, for ComboBox they are ComboBoxItems. What type are they for an ItemsControl? I've been digging through Blend's templates to no avail.

I wish to create a new ControlTemplate for the items inside the ItemsControl.

To clarify with code:

EDIT: Figured out the type as shown below:

<UserControl.Resources>
    <Style x:Key="TemplateStyle" TargetType="{x:Type ContentControl}"> <!-- Here I need the correct Type in the TargetType-tag -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContentControl}"> <!-- Again, I need the correct Type in a TargetType-tag -->
                    <DockPanel>
                        <TextBlock Text="Header" DockPanel.Dock="Top"/>
                        <ContentPresenter/>
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
</UserControl.Resources>
<ItemsControl ItemContainerStyle="{StaticResource TemplateStyle}"/>
A: 

It's simply a ContentPresenter, which implies it will be rendered with whatever DataTemplate is associated with the type.

If you want to take explicit control over how the items are rendered, you can just use ItemTemplate:

<ItemsControl ItemsSource="{Binding Customers}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

HTH,
Kent

Kent Boogaart
I need to set behaviour aside from the ItemTemplate (which is variable) - so, I need control over the ControlTemplate, but I'll try and see if I can hit it with a x:TypeOf ContentPresenter.EDIT: That doesn't work as TargetType in the Style - I'll clarify my question.
Goblin
To clarify - the Item inside the ItemsControl must be something with a Template-property - ContentPresenter does not.
Goblin
A: 

I figured it out by trial and error. The type inside the ItemsControl is some kind of ContentControl (probably just a ContentControl). I'll update the question for others.

Goblin