无效不隐藏标签(Invalidate doesn't hide tabs)

2019-11-01 07:51发布

我试图把我的流利色带/ RibbonUI系统的认识的极限在Office 2007/2010框架。

耦合与我的XAML设计WPF / Silverlight的认识和了解,我想看看我是否能动态显示/隐藏在下面所描述的Office菜单项目,似乎我已经FUBAR'd的东西了。

请告诉我哪里错了,或者我需要进一步发展:

CustomUI.xml

<group id="grpITOfficeMenu"
            label="Office Menu">
    <button id="btnShowOffice"
                label="Show"
                onAction="ShowOfficeTabs"/>
    <button id="btnHideOffice"
                label="Hide"
                onAction="HideOfficeTabs" />
</group>
<group id="grpITContextualTabs"
            label="Contextual Tabs" >
    <button id="btnShowContext" 
                label="Show" 
                onAction="ShowContextualTabs"/>
    <button id="btnHideContext"
                label="Hide"
                onAction="HideContextualTabs"/>
</group>
...
<officeMenu>
    <button idMso="FileNew"
                getVisible="OfficeGetVisible" />
    <button idMso="FileOpen"
                getVisible="OfficeGetVisible" />
</officeMenu>
<contextualTabs>
    <tabSet idMso="TabSetSmartArtTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetChartTools"
                getVisible="ContextualGetVisible"/>
    <tabSet idMso="TabSetDrawingTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetPictureTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetPivotTableTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetHeaderAndFooterTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetTableToolsExcel"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetPivotChartTools"
                getVisible="ContextualGetVisible" />
    <tabSet idMso="TabSetInkTools"
                getVisible="ContextualGetVisible" />
</contextualTabs>

VBA:

'Method to Refresh the RibbonUI object
Sub RefreshRibbon(tag As String)
   'Check if Ribbon variable has been initialized with Ribbon Object from Excel
   If Not (Rib Is Nothing) Then
      'Ribbon variable has been initialized.
      MyTag = tag
      Rib.Invalidate
   End If
End Sub
'Flip OfficeMenu Tabs visible based on @OffVisible value
Sub OfficeGetVisible(control As IRibbonControl, ByRef returnVal)
   returnVal = OffVisible
End Sub
'Flip Contextual Tabs visible based on @ContVisible value
Sub ContextualGetVisible(control As IRibbonControl, ByRef returnVal)
   returnVal = ContVisible
End Sub
...
'Show/Hide ContextualTabs in the IT Mode
Sub ShowContextualTabs(Optional ctrl As Variant)
   ContVisible = True
   RefreshRibbon tag:=MyTag
End Sub
Sub HideContextualTabs(Optional ctrl As Variant)
   ContVisible = False
   RefreshRibbon tag:=MyTag
End Sub
'Show/Hide OfficeMenu Tabs in the IT Mode
Sub ShowOfficeTabs(Optional ctrl As Variant)
   OffVisible = True
   RefreshRibbon tag:=MyTag
End Sub
Sub HideOfficeTabs(Optional ctrl As Variant)
   OffVisible = False
   RefreshRibbon tag:=MyTag
End Sub

更新:

做了一些详细的测试,它在技术上的作品,但我努力,最终完成是显示/隐藏能力的Home, Insert, Page Layout, Formulas, Data, Review, View, Developer, etc.选项卡从功能区。 我试图删除的需要,或者必要时,的startfromscratch在属性customui元素。

Answer 1:

得到它解决了,不得不去看看所有的的idMso两个值TabSetsTab功能区中的对象。

因此,这里是XML的CustomUI允许的一些默认的显示/隐藏(至少我所需要的那些)选项卡/标签集的。 采用上述相同的显示/隐藏方法。

<customUI onLoad="s_UIOnLoad" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon>
    <!-- Excel File Menu options, not available through Tab or TabSets -->
    <officeMenu>
      <button idMso="FileNew" getVisible="OfficeGetVisible" />
      <button idMso="FileOpen" getVisible="OfficeGetVisible" />
    </officeMenu>
    <!-- Excel TabSets that only become visible when certain objects
    are selected (such as ListObjects, PivotTables, Charts, etc) -->
    <contextualTabs>
      <tabSet idMso="TabSetChartTools" getVisible="ContextualGetVisible"/>
      <tabSet idMso="TabSetDrawingTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetEquationTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetHeaderAndFooterTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetInkTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetPictureTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetPivotChartTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetPivotTableTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetSlicerTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetSmartArtTools" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetSparkline" getVisible="ContextualGetVisible" />
      <tabSet idMso="TabSetTableToolsExcel" getVisible="ContextualGetVisible" />
    </contextualTabs>
    <tabs>
      <!-- Excel Menu Tabs, these are not included in the TabSets and
    must be explicitely defined -->
      <tab idMso="TabAddIns" getVisible="OfficeGetVisible" />
      <tab idMso="TabBackgroundRemoval" getVisible="OfficeGetVisible" />
      <tab idMso="TabData" getVisible="OfficeGetVisible" />
      <tab idMso="TabDeveloper" getVisible="OfficeGetVisible" />
      <tab idMso="TabFormulas" getVisible="OfficeGetVisible" />
      <tab idMso="TabHome" getVisible="OfficeGetVisible" />
      <tab idMso="TabInsert" getVisible="OfficeGetVisible" />
      <tab idMso="TabPageLayoutExcel" getVisible="OfficeGetVisible" />
      <tab idMso="TabReview" getVisible="OfficeGetVisible" />
      <tab idMso="TabView" getVisible="OfficeGetVisible" />
      ...
    </tabs>
  </ribbon>
</customUI>


Answer 2:

白手起家

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon  startFromScratch="true"/>
</customUI>

它消除了一切,但后台。

如果你想带一些人的回应

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon  startFromScratch="true">
    <tabs>
      <tab idMso="TabView" visible="true"/>
    </tabs>
  </ribbon>
</customUI>


文章来源: Invalidate doesn't hide tabs