Showing TeamExplorer Navigation Item only when connected to a Team Project

Sep 9, 2013 | Utkarsh Shigihalli

Extensions VisualStudio

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.


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;
            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
Author Image
Utkarsh Shigihalli
Utkarsh is passionate about software development and has more than 12 years of work experience in the areas of Azure, VSTS, C# and TypeScript. He has developed numerous extensions for Visual Studio and Visual Studio Team Services. He is currently working as a Consultant in the United States.