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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:09:28+00:00 2026-05-12T11:09:28+00:00

I have a tab control bound to an observablecollection for dynamic tabs as follows:

  • 0

I have a tab control bound to an observablecollection for dynamic tabs as follows:

<TabControl ItemsSource="{Binding AllTabs}" SelectedIndex="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        <TabControl.ItemTemplate>
            <DataTemplate>
                   <!--.............. -->
            </DataTemplate>
        </TabControl.ItemTemplate>

        <TabControl.ContentTemplate>
            <DataTemplate DataType="{x:Type vm:TabViewModel}">
                <c:MyTabItem/>
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>

So, the tab headers and contents are defined dynamically and assigned as the observable collection changes. Now, I would like to hide some tabs without deleting them in the collection behind – in order to keep the data should the tab reopen.

Ideally, each chat tab viewmodel has a IsVisible property that is set to true by default. However, where do I bind such a property to in order to make a tab item collapse?

  • 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-12T11:09:28+00:00Added an answer on May 12, 2026 at 11:09 am

    If you can modify your vm:TabViewModel I should change your IsVisible to a Visibility property and use the following ContentTemplate:

    <TabControl.ContentTemplate>
        <DataTemplate DataType="{x:Type vm:TabViewModel}">
            <c:MyTabItem Visibility={Binding Visibility}/>
        </DataTemplate>
    </TabControl.ContentTemplate>
    

    Else you could use a converter to change the boolean IsVisible to an Visibility enum:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Data;
    using System.Windows;
    
    namespace Something.Converters
    {
        [ValueConversion(typeof(bool), typeof(Visibility))]
        public class BoolToVisibilityConverter : IValueConverter
        {
    
            #region IValueConverter Members
            /// <summary>
            /// Converts a value.
            /// </summary>
            /// <param name="value">The value produced by the binding source.</param>
            /// <param name="targetType">The type of the binding target property.</param>
            /// <param name="parameter">The converter parameter to use.</param>
            /// <param name="culture">The culture to use in the converter.</param>
            /// <returns>
            /// A converted value. If the method returns null, the valid null value is used.
            /// </returns>
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value is bool && targetType == typeof(Visibility))
                {
                    bool val = (bool)value;
                    if (val)
                        return Visibility.Visible;
                    else
                        if (parameter != null && parameter is Visibility )
                            return parameter;
                        else
                            return Visibility.Collapsed;
                }
                throw new ArgumentException("Invalid argument/return type. Expected argument: bool and return type: Visibility");
            }
    
            /// <summary>
            /// Converts a value.
            /// </summary>
            /// <param name="value">The value that is produced by the binding target.</param>
            /// <param name="targetType">The type to convert to.</param>
            /// <param name="parameter">The converter parameter to use.</param>
            /// <param name="culture">The culture to use in the converter.</param>
            /// <returns>
            /// A converted value. If the method returns null, the valid null value is used.
            /// </returns>
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value is Visibility && targetType == typeof(bool))
                {
                    Visibility val = (Visibility)value;
                    if (val == Visibility.Visible)
                        return true;
                    else
                        return false;
                }
                throw new ArgumentException("Invalid argument/return type. Expected argument: Visibility and return type: bool");
            }
            #endregion
        }
    }
    

    Inculde the namespace in your xaml (your root element, Window in this example):

    <Window xmlns:converters="clr-namespace:Something.Converters"
    .../>
    

    And in your resources:

    <Window.Resources>
        <converters:BoolToVisibilityConverter x:Key="boolToVisibilityConverter"/>
    </Window.Resources>
    

    And finaly the binding:

    <TabControl.ContentTemplate>
        <DataTemplate DataType="{x:Type vm:TabViewModel}">
            <c:MyTabItem Visibility={Binding IsVisible, Converter={StaticResource boolToVisibilityConverter}, ConverterParameter=Visibility.Collapsed}/>
        </DataTemplate>
    </TabControl.ContentTemplate>
    

    I think thats it 🙂

    Edit: Ow and change the ConverterParameter to Visibility.Collapsed to Visibility.Hidden for hidden 😉

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

Sidebar

Related Questions

I have a data bound tab control: <TabControl ItemsSource={Binding Products} Name=ProductsTabControl> <TabControl.ItemTemplate> <DataTemplate> <TextBlock
I have a TabControl whose items are bound to an ObservableCollection : <TabControl ItemsSource={Binding
I have a tab control: <TabControl IsSynchronizedWithCurrentItem=True ItemsSource={Binding} ItemTemplate={StaticResource ClosableTabItemTemplate} > </TabControl> I want
Say I have XAML like <TabControl Grid.Row=1 Grid.Column=2 ItemsSource={Binding Tabs} IsSynchronizedWithCurrentItem=True> <TabControl.ItemTemplate> <DataTemplate> <TextBlock
Problem I have a custom tab control using Chrome-shaped tabs that binds to a
I have a UserControl with a Tab Control containing three tabs. Within the tabs
I have a tab control on a form, and a couple different tabs have
I have a tab control with two tabs. Both tabs have controls which are
Hi I have a tab control which is bound to a collection property of
I have Tab Control, with two tabs, and each tab contains a UserControl, the

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.