R – WPF – ItemTemplate not acting as expected


I have a UserControl which I'm using to display a list of UIElements. The control consists of a single ItemsControl with it's ItemPanelTemplate switched for a horizontal StackPanel, its ItemsSource bound to a DependencyProperty exposed by the UserControl and its ItemTemplate set in the UserControl.Resources.

Everything works fine except the ItemTemplate never get's applied and I can't see why. The full source is below.

UserControl.xaml –

<UserControl x:Name="UC" x:FieldModifier="private" x:Class="ContentSliderControl.ContentSlider"

    <DataTemplate x:Key="pageTemplate">
        <Border CornerRadius="10" Padding="5" Height="200" Width="200" Background="#333">
            <ContentControl Content="{Binding}"/>

    <ItemsPanelTemplate x:Key="template">
        <StackPanel IsItemsHost="True"

<ItemsControl ItemsPanel="{StaticResource template}" 
              ItemTemplate="{StaticResource pageTemplate}" 
              ItemsSource="{Binding ElementName=UC,Path=Pages}"/>

UserControl.xaml.cs –

public partial class ContentSlider : UserControl

    public List<UIElement> Pages
        get { return (List<UIElement>)GetValue(PagesProperty); }
        //set { SetValue(PagesProperty, value); }

    // Using a DependencyProperty as the backing store for Pages.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty PagesProperty =
        DependencyProperty.Register("Pages", typeof(List<UIElement>), typeof(ContentSlider), new UIPropertyMetadata(null));

    public ContentSlider()


I consume the control in my main window like this –

    <slider:ContentSlider >

The buttons appear fine but not inside the 200px square border.

Any help would be greatlly appriciated.

Best Solution

It's because it's a list of UIElement, the item template is only applied if the items can't be displayed directly.

Related Question