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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:21:56+00:00 2026-05-11T12:21:56+00:00

What is the most minimal way to dynamically interchange UIElement s at a certain

  • 0

What is the most minimal way to dynamically interchange UIElements at a certain ‘slot’ on the UI? I have a number of UIElements and based on some external databinding (e.g. a combobox selection) I want one of them to be shown and the one that was currently visible to be hidden. So the behavior is sort of like the TabControl but without the tabstrip, the chrome and the tabitem instances. So I could actually use the TabControl and override the control template. But is this really the most minimal approach?

  • 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. 2026-05-11T12:21:56+00:00Added an answer on May 11, 2026 at 12:21 pm

    You have several options. As Bryan mentioned, Data Template Selectors can definitely work, although I’ve decided that they are frequently overkill. Take your example for instance – if you want to bind the visibility of an element to the selection in a ComboBox, I would prefer a ValueConverter instead. Pass the ComboBox.SelectedItem to the Converter and have it return a Visibility value:

    public class MyObjectToVisibleOrCollapsed : IValueConverter {     #region IValueConverter Members     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)     {         if (value is MyObject)         {             var myObject = (MyObject)value;             if (myObject.SomeState)             {                 return Visibility.Visible;             }         }          return Visibility.Collapsed;     }      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)     {         throw new NotImplementedException();     }      #endregion } 

    Now in your Window.Resources, create an instance of the ValueConverter and Bind the Element to the ComboBox.SelectedItem using the ValueConverter instance:

    <local:MyObjectToVisibleOrCollapsed x:Key='myObjectToVisibleOrCollapsed'/> <DataTemplate x:Key='MyTemplate'>     <TextBlock Text='{Binding Path=myText}'                 x:Name='MyText'                 Visibility='{Binding ElementName=MyComboBox, Path=SelectedItem, Converter={StaticResource myObjectToVisibleOrCollapsed}, Mode=Default}' /> </DataTemplate> 

    And of course you can reuse the ValueConverter for all the elements in your DataTemplate (and if there are a lot of them, then the Data Template Selector approach becomes more desirable).

    [Disclaimer: the code above was hashed out from memory and not tested – it may need a little tweaking]

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

Sidebar

Related Questions

I have to write a number of queries in SQL Server Management Studio, most
What is the most proper way to sending email of minimal 1000 or more
I'm looking for the most efficient way to calculate the minimum number of bytes
I have to maintain a number of minor legacy apps and most of them
Most databases support some form of insert into select... statement. insert into a select
Most of the ASP.NET MVC paging solutions I have found by googling look like
We're building a site that will have very minimal code, it's mostly just going
I have a long-lived server application that is designed to run with minimal downtime
I encountered a problem which I need some help with - suppose I have
Is this the most efficient way to listen to mouse events on the background

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.