Geeks With Blogs

News

 Subscribe



Utkarsh Shigihalli Microsoft MVP and Microsoft ALM Ranger writing on Visual Studio Extensibility, ALM and .NET

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 obivious 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.

  1. In the Invalidate method of your Navigation Item class get the instance of the ITeamFoundationContextManager.
    var teamFoundationContextManager = _serviceProvider.GetService(typeof(ITeamFoundationContextManager)) as ITeamFoundationContextManager;
  2. 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.

Posted on Monday, September 9, 2013 2:07 PM .NET , Visual Studio Integrate , VSX | Back to top


Comments on this post: Showing TeamExplorer Navigation Item only when connected to a Team Project

comments powered by Disqus

Copyright © Utkarsh Shigihalli | Powered by: GeeksWithBlogs.net