0

平台:Office 2019 应用:Microsoft Word

我们创建了一个显示在 Backstage 视图中的自定义选项卡。

但是,我们希望在后台视图打开时将焦点设置在此选项卡上。该选项卡恰好出现在我们想要的位置并且可以正常工作,但我们希望它被选中。

我试过的

        public void OnShow(object contextObject)
        {

            try
            {

                this.ribbon.ActivateTab("OurCustomTab");
            }
            catch(Exception e )
            {
                MessageBox.Show(e.ToString());
            }


        }

上面的代码返回一条消息,说明我提供的值超出范围。

我需要知道的是如何找到自定义选项卡的控件 ID。

自定义 XML

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <commands>
    <command idMso="FileSave" onAction="FileSaveOverride"/>
    <command idMso="FileSaveAs" onAction="FileSaveAsOverride"/>
  </commands>

  <backstage onShow="OnShow">

    <tab id="OurCustomTab" label="CUSTOM" insertBeforeMso="TabInfo" title="OUR TAB" tag ="OUR" getVisible="IsOURTabVisible" >
      <firstColumn>

        <group id="OURSave" label="Save" helperText="Performs Save operation for OUR documents">
          <primaryItem>
            <button id="OurCustomSaveButton" label="Save" imageMso="FileSave" isDefinitive="true" onAction="CustomSaveOverride" />
          </primaryItem>
        </group>

        <group id="OurSaveAs" label="Save As" helperText="Performs Save As operation for OUR documents">
          <primaryItem>
            <button id="OurCustomSaveAsButton" label="Save As" imageMso="FileSaveAs" isDefinitive="true" onAction="CustomSaveAsOverride" />
          </primaryItem>
        </group>

      </firstColumn>
    </tab>


  </backstage>
</customUI>
4

1 回答 1

0

看起来ActivateTab在这种情况下不起作用。

Microsoft Active Accessibility 和 Microsoft UI Automation 在这里也不起作用。看起来控件在调用“OnShow”回调时没有加载。

我的测试方法是运行一个单独的可执行文件,该文件能够将焦点设置在 Backstage 视图中的自定义选项卡上。相同的代码在 VSTO 外接程序中不起作用。

由于运行单独的可执行文件超出了我们项目的范围,我只是求助于使用 SendKeys;不是我最喜欢的选择,但它有效。

于 2019-10-07T19:22:21.947 回答