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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:13:21+00:00 2026-06-01T08:13:21+00:00

I have a ComboBox bound to a collection of objects defined as this. public

  • 0

I have a ComboBox bound to a collection of objects defined as this.

public class TierOption
{
    public string Option { get; set; }
    public Type DataType { get; set; }
}
public class TierOptions : ObservableCollection<Tier1Option>
{

}

I have 3 other controls related to this ComboBox, which are a TextBox, ComboBox, or a WPFToolKit:DatePicker.

I need to show only the related control which corresponds to the datatype(Type) of the object selected in the first ComboBox and neither of the others.

Pseudo Code Example:
(Probably too close to butchered C# but hopefully it conveys the idea)

switch (ComboBox.SelectedItem.DataType)
{
     case String:
          TextBox.Visibility = Visibility.Visible;
          ComboBox.Visibility = Visibility.Hidden;
          DatePicker.Visibility = Visibility. Hidden;
     break;
     case DateTime:
          TextBox.Visibility = Visibility.Hidden;
          ComboBox.Visibility = Visibility.Hidden;
          DatePicker.Visibility = Visibility. Visible;
     break;
     <...so forth and so on...>
}

My attempts have resulted in very non-wpf looking convoluted messes which don’t work regardless. Being new to wpf I’m trying very hard to stay true to the best design practices.

Thank you!

  • 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-01T08:13:23+00:00Added an answer on June 1, 2026 at 8:13 am

    You can play with DataTemplate with DataType property

    <...Resources>
        <DataTemplate DataType="{x:Type sys:String}">
            <TextBox Text="{Binding}"/>
        </DataTemplate>
        <DataTemplate DataType="{x:Type DateTime}">
            <DatePicker .../>
        </DataTemplate>
        ...
    </...Resources>
    
    <ContentControl Content="{Binding SelectedItem, ElementName=myComboBox}"/>
    
    <ComboBox ItemsSource="{Binding ...}"/>
    

    The code above is just the idea, you could have to make adjustements. For example you won’t be able to modify a string item itself (you could have to encapsulate each item of your list)

    If your list contains all items of the same type, you can use a ContentTemplateSelector on contentControl.

     ContentControl Content="{Binding SelectedItem, ElementName=YourCombBox}" ContentTemplateSelector="{StaticResource YourTemplateSelector}"
    

    MSDN DOC about ContentControl.ContentTemplateSelector Property

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

Sidebar

Related Questions

I have a ComboBox that is bound to a collection of CLR objects. Each
I have a ComboBox with its Items property bound to a collection of objects.
I have a ComboBox with a list of objects bound to it. Currently i
I have a ComboBox with a label function like this one: private function fieldLabelFunction(item:Object):String
I have a small problem. I have a set of ComboBox's that are bound
I have a WPF ComboBox bound to a Collection List<Users> . I have applied
This should be easy but it's not working. I have a WPF combobox bound
To clarify I have a combobox with an observable collection bound to its itemsource
I have a combobox bound to a collection, so the user can select one
I have a combobox that is bound to an enum using the following code:

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.