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 7872749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:18:09+00:00 2026-06-03T02:18:09+00:00

I created a dbml file, which automatically created the designer.cs In the designer.cs (which

  • 0

I created a dbml file, which automatically created the designer.cs

In the designer.cs (which is the Model in the MVVM) there are two different classes in the database:
ElementA and ElementB.

I have two user controls:
Element_A_UserControl – displays a single instance of ElementA
Element_B_UserControl – displays a single instance of ElementB

There is another user control that has two stack panels.
The first stack panel displays a list of Element_A_UserControl
The second stack panel displays a list of Element_B_UserControl

Here is the stack panel #1 XAML:

<StackPanel>
    <ItemsControl ItemsSource="{Binding AllElements_A}">
         <ItemsControl.ItemTemplate>
                <DataTemplate>
                     <vw:Element_A_UserControl x:Name="elementA">                            
                     </vw:Element_A_UserControl>
                 </DataTemplate>
          </ItemsControl.ItemTemplate>
     </ItemsControl>
</StackPanel>

Here is the stack panel #2 XAML:

<StackPanel>
    <ItemsControl ItemsSource="{Binding AllElements_B}">
         <ItemsControl.ItemTemplate>
                <DataTemplate>
                     <vw:Element_B_UserControl x:Name="elementB">                            
                     </vw:Element_B_UserControl>
                 </DataTemplate>
          </ItemsControl.ItemTemplate>
     </ItemsControl>
</StackPanel>

Up to now everything works fine.

I want to have one stack panel, which displays a list of ElementA or a list of ElementB depending of a condition.

Note: The property to get list of elements is different.
i.e.

ItemsSource="{Binding AllElements_A}
ItemsSource="{Binding AllElements_B}

I hope that my question is clear enough.

Dazy.

  • 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-03T02:18:11+00:00Added an answer on June 3, 2026 at 2:18 am

    One way is that you could try to use a conditional DataTemplate. Something like this:

    <ItemsControl.Resources>
        <DataTemplate DataType="{x:Type local:ElementAType}">
             <vw:Element_A_UserControl x:Name="elementA">                            
             </vw:Element_A_UserControl>
        </DataTemplate>
    
        <DataTemplate DataType="{x:Type local:ElementBType}">
             <vw:Element_B_UserControl x:Name="elementB">                            
             </vw:Element_B_UserControl>
        </DataTemplate>
    </ItemsControl.Resources>
    

    Then, in your viewmodel, create:

    public ObservableCollection<object> CombinedCollection {get; set;}
    

    and load it with either of your collections conditionally.

    Alternatively, keep both ItemsControls in your XAML, and conditionally hide/show them using Visibility and a BooleanToVisibilityConverter. Given these two choices, I would likely choose this one, as it is clearer in the code, and easier to maintain than the conditional DataTemplate above. However, you seemed to indicate that you didn’t want to do that, so I presented the first one as an option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to put some of the entities created via a.dbml Linq-To-Sql file into
So I've created a dbml in my project, which has three tables: Elements, ElementImages
I created a batch file to run SqlMetal and generate Linq2Sql data classes, check
I was reading Linq to Sql. Here I created a dbml file where I
I've created a DBML file for a LINQ to SQL mapping and after dragging
I have a database, I create a dbml file and drop the tables it.
I have created a smalldatetime field. I am using a dbml file to access
I have a dbml file (linq to sql) to connect to my database. I
I've got a problem with Linq in VB.NET. I've created a .dbml file from
I have the following 3 classes in my dbml file: public class Player {

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.