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

  • Home
  • SEARCH
  • 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 7430507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:09:06+00:00 2026-05-29T09:09:06+00:00

Here is what I am trying to do. I have 2 Data Templates defined

  • 0

Here is what I am trying to do. I have 2 Data Templates defined which both refer to a different user control.

<UserControl.Resources>
    <DataTemplate x:Key="myDataTemplate1">
        <Border BorderBrush="Black" BorderThickness="1">
            <myUserControl1 />
        </Border>
    </DataTemplate>
    <DataTemplate x:Key="myDataTemplate2">
            <Border BorderBrush="Black" BorderThickness="1">
                <myUserControl2/>
            </Border>
    </DataTemplate>
</UserControl.Resources>

I am using these Data Templates to display a list of items using ItemsControl like this:

<ItemsControl x:Name="myItemList" ItemTemplate="{StaticResource myDataTemplate1}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate />
    </ItemsControl.ItemsPanel>
</ItemsControl>

I would like the ItemTemplate to conditionally be either myDataTemplate1 or myDataTemplate1 depending on the value of an integer variable being 1 or 2 respectively.

Should I use DataTriggers for this or is there another way to do this? Appreciate the help.

  • 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-05-29T09:09:07+00:00Added an answer on May 29, 2026 at 9:09 am

    Don’t set the ItemTemplate but use an ItemTemplateSelector.

    DataTriggers would be fine too of course, spares you the extra class for the selector. e.g.

    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <ContentControl Content="{Binding}">
                <ContentControl.Style>
                    <Style TargetType="ContentControl">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ThatProperty}" Value="1">
                                <Setter Property="ContentTemplate"
                                        Value="{StaticResource myDataTemplate1}" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding ThatProperty}" Value="2">
                                <Setter Property="ContentTemplate"
                                        Value="{StaticResource myDataTemplate2}" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's what I'm trying to do, and failing... I have a File model which
I have a user control with a property defined as follows: public partial class
Here's what I'm trying to do : I have an entity Task with a
Here is a problem I am trying to solve: I have an irregular shape.
here's what I'm trying to do : On a page, I would have a
Here is what I am trying to do. I have a block of text
Here's what I'm trying to do. I have an ASP.NET MVC web application, where
I have an interesting problem here I've been trying to solve for the last
Here's what i'm trying to do. I have a project in /var/www/project. I'd like
Here is my custom class that I have that represents a triangle. I'm trying

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.