Team Explorer in Visual Studio 2012 displays many context sensitive navigation items and links. If you would like to know what are navigation items and links take a look at the below picture.

image

The team explorer shows certain navigation items (for example: My Work, Pending Changes etc) only when you are connected to TFS. These items are hidden (for obvious reasons) when you are not connected.

In this blog post I will show you how to to hide/show the your custom navigation items in team explorer similar to other default navigation items. For how to extend Team Explorer (to create your own navigation items, links), please go through this post by Microsoft.

var teamFoundationContextManager = _serviceProvider.GetService(typeof(ITeamFoundationContextManager)) as ITeamFoundationContextManager;
  • Validate returned context to see if it has HasTeam = true. HasTeam property will be true only when connected to a team project. If it is false (meaning, we are not connected to TFS), we set the visibility of our navigation item to false.
if (teamFoundationContextManager != null && teamFoundationContextManager.CurrentContext != null)
    {
        if (teamFoundationContextManager.CurrentContext.HasTeam)
        {
            IsVisible = true;
        }
        else
        {
            IsVisible = false;
        }
    }

That’s it! With just by above code, your navigation item will be shown only when you are connected to a team project.


About author
Utkarsh Shigihalli
Utkarsh Shigihalli
Utkarsh is passionate about software development and has experience in the areas of Azure, Azure DevOps, C# and TypeScript. Over the years he has worked as an architect, independent consultant and manager in many countries including India, United States, Netherlands and United Kingdom. He is a Microsoft MVP and has developed numerous extensions for Visual Studio, Visual Studio Code and Azure DevOps.
We Are
  • onlyutkarsh
    Utkarsh Shigihalli
    Microsoft MVP, Technologist & DevOps Coach


  • arora_tarun
    Tarun Arora
    Microsoft MVP, Author & DevOps Coach at Avanade

Do you like our posts? Subscribe to our newsletter!
Our Book