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.
- In the Invalidate method of your Navigation Item class get the instance of the ITeamFoundationContextManager.
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.