加载特定文档时如何禁用 Word 的内置功能区选项卡? [英] How can I disable Word's built-in Ribbon Tabs when a specific document is loaded?

查看:28
本文介绍了加载特定文档时如何禁用 Word 的内置功能区选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用以下代码:

I am using the following code right now:

<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<commands>
<command idMso="Font" enabled="false"/>
<command idMso="AlignLeft" enabled="false"/>
<command idMso="AlignCenter" enabled="false"/>
<command idMso="AlignRight" enabled="false"/>
</commands>

等等,但这显然会完全禁用按钮.我现在希望限制我的用户在加载特定文档时无法使用某些内置 Word 控件,并让他们在其余时间可以自由地做任何事情.我曾尝试使用:

and so on, but this completely disables the buttons obviously. I now want to restrict my users from being able to use certain built-in Word controls when a specific document is loaded, and leave them with the liberty of doing whatever the rest of the time. I have tried to use:

<command idMso="FontSize" getEnabled="checkDisable"/>

where checkDisable 检查哪些文档是打开的.然后在该文档中搜索一个字符串(这就是我知道我想禁用按钮的方式),但是在实际加载文档之前会触发 checkDisable 回调.我可以以某种方式直接从代码隐藏而不是仅通过 XML 禁用特定按钮吗?如果我能做到这一点,我就可以禁用 DocumentLoaded 事件上的按钮.

where checkDisable checks for what documents are open. That document is then searched for a string (that's how I know I want to disable the buttons), but the checkDisable callback fires before the document is actually loaded. Can I somehow directly disable specific buttons from the codebehind instead of just via XML? If I could do this, I could disable the buttons on the DocumentLoaded event.

感谢任何建议,我一直在用头撞墙在谷歌上搜索这个好几个小时.

ANY suggestions are appreciated, I've been banging my head against the wall Googling this one for hours.

推荐答案

您来对地方了.您需要使用回调而不是属性.但是 Office 会缓存这些值,并且不会根据需要每次都调用回调.相反,要刷新 UI(强制 Office 应用程序调用回调),您需要使用 无效InvalidateControl IRibbonUI 界面的方法.有关详细信息,请参阅IRibbonUI 对象概述.

You are on the right avenue. You need to use callbacks instead of attributes. But Office caches the values and don't call the callbacks each time as you want it. Instead, to refresh the UI (force Office application to invoke callbacks) you need to use the Invalidate or InvalidateControl methods of the IRibbonUI interface. See Overview of the IRibbonUI Object for more information.

例如,当您在宿主应用程序中打开一个新文档时,打开 事件被触发.您可以查看 Document 并调用 Invalidate 方法(如果需要)来强制主机应用程序调用您的回调,从而刷新 UI.

For example, when you open a new document in the host application the Open event is fired. You can check out the Document and call the Invalidate method (if required) to force the host application to call your callbacks and therefore refresh the UI.

这篇关于加载特定文档时如何禁用 Word 的内置功能区选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆