none
Bug in TabControl/TabItem`s content visibility?

    Question

  • I use .NET 3 RTM.

    I have TabControl with TabItems.

    When I hide a TabItem (Visibility = Collapsed) and do not select another tab (sometimes I hide all tabs so I cannot select any tab), content of hidden TabItem is still visible.

    Thursday, November 09, 2006 2:07 PM

All replies

  • yes, I think it is a bug, and there are more than few issues here

    For ex.

    <TabControl>        

                  <TabItem Header="Item1" Visibility="Hidden">Item1 content</TabItem>

                  <TabItem Header="Item2" Visibility="Hidden" >Item2 content</TabItem>

           </TabControl>

    'Item1 Content' is still visible

    <TabControl>        

                  <TabItem Header="Item1" Visibility="Hidden">Item1 content</TabItem>

                  <TabItem Header="Item2"  >Item2 content</TabItem>

           </TabControl>

    first tabitem is not visible but its content is visible

    Thursday, November 09, 2006 2:24 PM
  • Hello everybody, it's not a bug, it's a normal behaviour of tabitem : when you hide (or collapse) it, nothing happens to its Content ; you have to hide (or collapse) the Content manually.
    For a complete explanation see:

    eggheadcafe - 11/1/2005 10:47:54 AM  Re: TabControl/TabItem bug?

    Bye


    --Daniele

     
    Wednesday, August 05, 2009 1:29 PM
  • I'm sure it is a great idea in theory. Back here on planet Earth I'm not so sure.
    Tuesday, June 07, 2011 7:40 PM
  • This should fix it: 
    <sdk:TabControl>
     <i:Interaction.Behaviors>
      <b:TabControlFixBehavior />
     </i:Interaction.Behaviors>
    public class TabControlFixBehavior : Behavior<TabControl>
    {
      protected override void OnAttached()
      {
        var tabControl = this.AssociatedObject;
    
        tabControl.Loaded += (sender, args) =>
          {
            var tabItems = tabControl.Items.Cast<TabItem>().ToList();
            var firstVisible = tabItems.FirstOrDefault(t => t.Visibility == Visibility.Visible);
            if (firstVisible != null && tabItems[tabControl.SelectedIndex].Visibility == Visibility.Collapsed)
            {
              tabControl.SelectedIndex = tabItems.IndexOf(firstVisible);
            }
          };
      }
    }
    


    Thursday, August 18, 2011 4:20 PM
  • sadly this idiotic behavior is still not fixed. When I set something to Collapsed I would think that it is indeed not visible.
    Wednesday, October 05, 2011 2:08 AM