[英]How can I disable Word's built-in Ribbon Tabs when a specific document is loaded?
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>
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. 我现在想限制我的用户在加载特定文档时不能使用某些内置的Word控件,并让他们可以在其余时间自由进行操作。 I have tried to use: 我尝试使用:
<command idMso="FontSize" getEnabled="checkDisable"/>
where checkDisable
checks for what documents are open. 其中checkDisable
检查打开了哪些文档。 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. 然后在该文档中搜索一个字符串(这就是我想禁用按钮的方式),但是在实际加载该文档之前会触发checkDisable回调。 Can I somehow directly disable specific buttons from the codebehind instead of just via XML? 我能以某种方式直接禁用代码背后的特定按钮,而不仅仅是通过XML吗? If I could do this, I could disable the buttons on the DocumentLoaded event. 如果可以这样做,则可以禁用DocumentLoaded事件上的按钮。
ANY suggestions are appreciated, I've been banging my head against the wall Googling this one for hours. 任何建议都值得赞赏,我一直在脑海中摸索着这个头几个小时。
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. 但是Office会缓存这些值,并且不会在每次需要时都调用回调。 Instead, to refresh the UI (force Office application to invoke callbacks) you need to use the Invalidate or InvalidateControl methods of the IRibbonUI interface. 相反,要刷新UI(强制Office应用程序调用回调),您需要使用IRibbonUI界面的Invalidate或InvalidateControl方法。 See Overview of the IRibbonUI Object for more information. 有关更多信息,请参见IRibbonUI对象概述 。
For example, when you open a new document in the host application the Open event is fired. 例如,当您在宿主应用程序中打开新文档时,将触发Open事件。 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. 您可以检出Document并调用Invalidate方法(如果需要)以强制主机应用程序调用您的回调,从而刷新UI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.