开发者

What is the type of elements inside an ItemsControl?

开发者 https://www.devze.com 2023-01-13 04:24 出处:网络
When I use a ListBox - the elements inside are of type ListBoxItem, for ComboBox they are ComboBoxItems. What type are they for an Items开发者_运维问答Control? I\'ve been digging through Blend\'s temp

When I use a ListBox - the elements inside are of type ListBoxItem, for ComboBox they are ComboBoxItems. What type are they for an Items开发者_运维问答Control? 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}"/>


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号