locked
Disable link in Team explorer (Visual studio 2012) RRS feed

  • Question

  • Hello,

    I am working on creating an extension to disable few links in Visual studio 2012 Team Explorer.Please see the below image for reference.I would like to disable the links highlighted in red color. 

    So far my work :

    I am able to get the Hyperlink field and properties info using reflection. But when I set the value it is not reflecting in UI. Please help me on this.

     var page = Tfs.TeamExplorer.CurrentPage;

                var sections = page.PageContent;
                Type type = typeof(System.Windows.Documents.Hyperlink);
                FieldInfo f1 = page.PageContent.GetType().GetField("linkCancelDecline", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static);
                object lateBound = Activator.CreateInstance(type);
                PropertyInfo[] test = f1.FieldType.GetProperties();
                object h = new System.Windows.Documents.Hyperlink();
                PropertyInfo info = test[54];
                info.SetValue(lateBound, Convert.ChangeType(false, info.PropertyType));



    Please someone help me.

    Thanks,

    Sree


    Sree

    Thursday, January 12, 2017 2:28 PM

Answers

  • Hi Sree85,

    Please modify your code like this:

     Microsoft.TeamFoundation.Controls.ITeamExplorer teamExplorer;
                Microsoft.TeamFoundation.Controls.ITeamExplorerPage page;
    
    
                teamExplorer = this.ServiceProvider.GetService(typeof(Microsoft.TeamFoundation.Controls.ITeamExplorer))
                   as Microsoft.TeamFoundation.Controls.ITeamExplorer;
    
                page = teamExplorer.CurrentPage;
    
    
                var sections = page.PageContent;
                Type type = typeof(System.Windows.Documents.Hyperlink);
                FieldInfo f1 = page.PageContent.GetType().GetField("linkCancelDecline", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static);
    
                PropertyInfo pinfo = sections.GetType().GetProperty("IsEnabled");
    
                pinfo.SetValue(sections, false, null);

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sree85 Wednesday, February 22, 2017 8:13 PM
    Friday, January 13, 2017 6:17 AM

All replies

  • Hello,

    I am working on creating an extension to disable few links in Visual studio 2012 Team Explorer.Please see the below image for reference.I would like to disable the links highlighted in red color. 

    So far my work :

    I am able to get the Hyperlink field and properties info using reflection. But when I set the value it is not reflecting in UI. Please help me on this.

     var page = Tfs.TeamExplorer.CurrentPage;

                var sections = page.PageContent;
                Type type = typeof(System.Windows.Documents.Hyperlink);
                FieldInfo f1 = page.PageContent.GetType().GetField("linkCancelDecline", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static);
                object lateBound = Activator.CreateInstance(type);
                PropertyInfo[] test = f1.FieldType.GetProperties();
                object h = new System.Windows.Documents.Hyperlink();
                PropertyInfo info = test[54];
                info.SetValue(lateBound, Convert.ChangeType(false, info.PropertyType));



    Please someone help me.

    Thanks,

    Sree


    Sree

    Wednesday, January 11, 2017 10:29 PM
  • Hi Sree85,

    Please modify your code like this:

     Microsoft.TeamFoundation.Controls.ITeamExplorer teamExplorer;
                Microsoft.TeamFoundation.Controls.ITeamExplorerPage page;
    
    
                teamExplorer = this.ServiceProvider.GetService(typeof(Microsoft.TeamFoundation.Controls.ITeamExplorer))
                   as Microsoft.TeamFoundation.Controls.ITeamExplorer;
    
                page = teamExplorer.CurrentPage;
    
    
                var sections = page.PageContent;
                Type type = typeof(System.Windows.Documents.Hyperlink);
                FieldInfo f1 = page.PageContent.GetType().GetField("linkCancelDecline", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static);
    
                PropertyInfo pinfo = sections.GetType().GetProperty("IsEnabled");
    
                pinfo.SetValue(sections, false, null);

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sree85 Wednesday, February 22, 2017 8:13 PM
    Friday, January 13, 2017 6:17 AM
  • Thank you Very much cole WU

    Sree

    Wednesday, February 22, 2017 8:13 PM
  • Hello,

    Thanks for your solution. Above code is disabling the complete section. Is there any possibility to just disable the "Close Review" link or handle the "OnClick" event of "Close Review" link? Please help me on this.

    Thanks,

    Sree


    Sree

    Thursday, February 23, 2017 2:36 PM