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.

Related Posts

About Utkarsh Shigihalli

Utkarsh is passionate about software development and has more than 10 years of work experience. He has developed numerous extensions for Visual Studio and Visual Studio Team Services. He is currently working as DevOps lead in one of the leading insurance company in United Kingdom