none
Show/hide different custom tabs, individually RRS feed

  • Question

  • I have my custom Ribbon tabs and I want to show or hide some of them upon given event. But I want to show/hide them individually, so the tabs should not be dependent on each other or anything like that.

    I've been trying the examples from this documentation. and this one but no success.

    This is the ribbon XML for the tabs:

    <tab id="t1" label="CustomTab" getVisible="GetVisible" tag="xtab">
          <!-- some other elements -->
    </tab>
    <tab id="t2" label="CustomTab_2" getVisible="GetVisible" tag="xtab_2">
       <!-- some other elements -->
    </tab>

    and the VB code:

    Private isVisible As Boolean = False
    
    Public Sub GetVisible(control As Office.IRibbonControl, ByRef returnedVal As Boolean)
       returnedVal = isVisible
    End Sub
    
    Private Sub RefreshRibbon(Tag As String)
       ribbon.Invalidate()
    End Sub
    
        Public Sub show_xtab(ByVal control As Office.IRibbonControl)
            isVisible = True
            Call RefreshRibbon(Tag:="xtab")
        End Sub
    
        Public Sub hide_xtab(ByVal control As Office.IRibbonControl)
            isVisible = False
            Call RefreshRibbon(Tag:="xtab")
        End Sub

    Here I'm trying just with one of them, to make at least that one to work (and then I'm gonna take care of passing the Tag attribute dynamically). But this does not work.

    However, if I change the GetVisible method to the following:

    Public Function GetVisible(control As Office.IRibbonControl)
        Return isVisible
    End Function

    it will work, but both of the tabs simultaneously. And I want to control them separately.

    Any suggestions or tutorials ?

    Update: tried some other solution:

    XML is still the same. VB code:

    Public MyTag as String
    
    Sub GetVisible(control As Office.IRibbonControl, ByRef visible As Boolean)
        If control.Tag Like MyTag Then
            visible = True
        Else
            visible = False
        End If
    End Sub
    
    Private Sub RefreshRibbon(Tag As String)
        MyTag = Tag
        ribbon.Invalidate()
    End Sub
    
    Public Sub show_xtab(ByVal control As Office.IRibbonControl)
        Call RefreshRibbon(Tag:="xtab")
    End Sub
    
    Public Sub show_xtab_2(ByVal control As Office.IRibbonControl)
        Call RefreshRibbon(Tag:="xtab_2")
    End Sub

    but still no success...


    Tuesday, June 2, 2015 8:19 AM

Answers