简体   繁体   English

加载特定文档后,如何禁用Word的内置功能区选项卡?

[英]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界面的InvalidateInvalidateControl方法。 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.

相关问题 如何将组添加到多个内置功能区选项卡 (vsto)? - How to add a group to multiple built-in Ribbon tabs (vsto)? 如何在功能区(Visual Designer)中禁用Excel内置的RibbonButton? - How to disable Excel built-in RibbonButton in Ribbon (Visual Designer)? 在 Word 插件项目中禁用 Word 文档功能区按钮的多个实例 - Multiple Instances of Word Document Ribbon button disable in Word Addin Project 如何拦截单击内置的Office功能区控件 - How to intercept clicking of a built-in Office Ribbon control 如何在C#中复制Python的已排序内置函数的行为? - How can I replicate the behavior of Python's sorted built-in function in C#? 如何覆盖 Serilog 在 Guid(或其他内置原语)上使用 ToString? - How can I override Serilog's use of ToString on Guid (or other built-in primitives)? 获取 Office Word 文档中所有功能区选项卡的列表 - Get list of all Ribbon tabs in Office Word document 如何禁用Excel内置RibbonButton? - How to disable Excel built-in RibbonButton? 如何将自定义TextBox样式应用于内置控件? - How can I apply a custom TextBox style to built-in controls? 如何在Linux上使用内置的Kinect驱动程序? - How can I use the built-in Kinect driver on Linux?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM