Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:15:54+00:00 2026-06-13T09:15:54+00:00

I am trying to create custom templated control based on a ListBox to display

  • 0

I am trying to create custom templated control based on a ListBox to display only the single selected item in the control’s collection.
To this aim, I have defined a Template with an ContentPresenter, databound to the SelectedItem property of the control.
As illustrated in scenario 1, it works well when providing the control with a collection of UIElement.

But when needing to use a DataTemplate to display an entity object, the ItemTemplate is ignored because the control has a Template which will prevent the `ItemTemplate from being used. From what I’ve read this is by design and it sorts of makes sense.

But how can I use DataTemplates for my control’s ItemTemplate and retain my control default template?

I have tried overriding PrepareContainerForItemOverride, and many different template configurations to no avail.

Here is some of what I tried:

<UserControl.Resources>

    <local:StringCollection x:Key="MyColors">
        <sys:String>Yellow</sys:String>
        <sys:String>Purple</sys:String>
    </local:StringCollection>

</UserControl.Resources>

<StackPanel Background="White">

    <TextBlock Margin="0,25,0,0">Scenario 1: Providing UIElements to the
        ControlTemplate's ContentPresenter: Works</TextBlock>
    <control:RotatingFlipView x:Name="Works" SelectedIndex="1">
        <control:RotatingFlipView.Template>
            <ControlTemplate>
                <ContentPresenter
                     Content="{Binding ElementName=Works, Path=SelectedItem}"/>
            </ControlTemplate>
        </control:RotatingFlipView.Template>
        <Rectangle Height="100" Width="100" Fill="Red"/>
        <Rectangle Height="100" Width="100" Fill="Blue"/>
        <Rectangle Height="100" Width="100" Fill="Green"/>
    </control:RotatingFlipView>

    <TextBlock Margin="0,25,0,0">Scenario 2: The ItemTemplate provided is ignored in
        favor of the RotatingFlipView's Template which displays the source as raw
        Strings</TextBlock>
    <control:RotatingFlipView x:Name="Broken"
                              ItemsSource="{StaticResource MyColors}">
        <control:RotatingFlipView.Template>
            <ControlTemplate>
                <ContentPresenter
                    Content="{Binding ElementName=Broken, Path=SelectedItem}"/>
            </ControlTemplate>
        </control:RotatingFlipView.Template>
        <control:RotatingFlipView.ItemTemplate>
            <DataTemplate>
                <Rectangle Height="100" Width="100" Fill="{Binding}"/>
            </DataTemplate>
        </control:RotatingFlipView.ItemTemplate>
    </control:RotatingFlipView>

    <TextBlock Margin="0,25,0,0">Scenario 3: Removing the RotatingFlipView's
        Template, causes the display to fall back on the ListBox's Template,
        though now my ItemTemplate is used:</TextBlock>
    <control:RotatingFlipView x:Name="Broken2"
                              ItemsSource="{StaticResource MyColors}">
        <control:RotatingFlipView.ItemTemplate>
            <DataTemplate>
                <Rectangle Height="100" Width="100" Fill="{Binding}"/>
            </DataTemplate>
        </control:RotatingFlipView.ItemTemplate>
    </control:RotatingFlipView>

</StackPanel>

RotatingFlipView.cs

public class RotatingFlipView : ListBox
{
    public RotatingFlipView()
    {
        DefaultStyleKey = typeof(RotatingFlipView);
    }
}

generic.xaml

<Style TargetType="local:RotatingFlipView">
    <Setter Property="SelectionMode" Value="Single"/>
    <Setter Property="SelectedIndex" Value="0"/>
</Style>

Output:
Output

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:15:55+00:00Added an answer on June 13, 2026 at 9:15 am

    I have now figured it out. Here is how I’ve done it:

    Mainpage.xaml

    <UserControl.Resources>
    
        <local:StringCollection x:Key="MyColors">
            <sys:String>Yellow</sys:String>
            <sys:String>Purple</sys:String>
        </local:StringCollection>
    
    </UserControl.Resources>
    
    <StackPanel Background="White">
        <control:RotatingFlipView>
            <Rectangle Height="100" Width="100" Fill="Red"/>
            <Rectangle Height="100" Width="100" Fill="Green"/>
            <Rectangle Height="100" Width="100" Fill="Blue"/>
        </control:RotatingFlipView>
    
        <control:RotatingFlipView ItemsSource="{StaticResource MyColors}">
            <control:RotatingFlipView.ItemTemplate>
                <DataTemplate>
                    <Rectangle Height="100" Width="100" Fill="{Binding}"/>
                </DataTemplate>
            </control:RotatingFlipView.ItemTemplate>
        </control:RotatingFlipView>
    <StackPanel/>
    

    RotatingFlipView.cs

    public class RotatingFlipView : ListBox    
    {    
        public RotatingFlipView()    
        {    
            DefaultStyleKey = typeof(RotatingFlipView);    
        }    
    }
    

    generic.xaml

    <Style TargetType="local:RotatingFlipView">
        <Setter Property="SelectionMode" Value="Single"/>
        <Setter Property="SelectedIndex" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:RotatingFlipView">
    
                    <ContentPresenter
                        Content="{TemplateBinding SelectedItem}"
                        ContentTemplate="{TemplateBinding ItemTemplate}"/>
    
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to create a custom renderer based on this Yehuda Katz's blog
I am trying to create a custom User library in CodeIgniter. Inside this library
I'm trying to create a templated control with Asp.Net MVC. By templated control, I
I'm trying to create a custom control (deriving from Control ) with its own
I'm trying to create a custom template tag that only renders a block of
I'm trying to dynamically create a datatemplate for a listbox. This is for a
I am trying to create different themes for a custom PropertyGrid control that inherits
I am trying to create a custom control, which behaves a bit like one
I'm trying to create a custom ListBox. That receives a list with three properties:
I'm trying to implement the Media Player custom field control described in this MSDN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.