如何使用Ribbon(Visual Designer)对象订阅Word后台的开放事件?

huangapple go评论63阅读模式
英文:

How can I subscribe to an Open event of a Word Backstage using a Ribbon (Visual Designer) object?

问题

我想在Word后台选项中添加一个按钮。该按钮应该只在Word中打开了一个或多个Word文档时才能启用/禁用。

有没有一些事件我可以使用来在后台选项显示时设置我的后台控件的状态?

注:作为一种解决方法,我可以订阅DocumentOpen事件,但不能订阅DocumentClose事件,因为它不存在。因此,这种解决方案不安全。

英文:

I want to add a button to the Word Backstage. That button is supposed to be enabled/disabled only when one or more Word documents are open in Word.

Is there some event I can use to set the state of my Backstage controls the moment the Backstage is displayed?

NB: As a workaround, I could subscribe to the DocumentOpen event, but not to a DocumentClose event, as it doesn't exist. So that solution isn't safe to use.

答案1

得分: 2

以下是翻译的部分:

The backstage UI provide the onShow callback which you may find helpful.
后台用户界面提供了onShow回调,您可能会发现它很有帮助。

Also you may find the onHide callback helpful:
您还可能会发现onHide回调很有帮助:

The callback should have the following signature:
回调应该具有以下签名:

public void Backstage_OnShow(object contextObject) {

}
您可以使用IRibbonUI.Invalidate方法来调用回调函数。例如,如果插件作者为按钮实现了getEnabled回调程序,该函数仅在加载状态时调用一次,然后如果需要更新状态,将使用缓存的状态而不是重新调用程序。这个过程保持不变,直到插件通过使用Invalidate方法发出缓存值无效的信号,此时再次调用回调程序并缓存返回响应。然后,插件可以通过调用Refresh方法强制立即更新用户界面。

Read more about that in the Dynamically Changing the Visibility of Groups and Controls in the Office 2010 Backstage View article.
Office 2010后台视图中动态更改组和控件的可见性文章中详细了解更多信息。

英文:

The backstage UI provide the onShow callback which you may find helpful.

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <backstage onShow="Backstage_OnShow">
    <tab idMso="TabSave">
...

Also you may find the onHide callback helpful:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
  <backstage onHide="onHide" onShow="onShow">
  ...
  </backstage>
</customUI>

The callback should have the following signature:

public void Backstage_OnShow(object contextObject) {
   
}

You can use the IRibbonUI.Invalidate method to get your callbacks invoked. For example, if an add-in writer implements the getEnabled callback procedure for a button, the function is called once, the state loads, and then if the state needs to be updated, the cached state is used instead of recalling the procedure. This process remains in place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.

Read more about that in the Dynamically Changing the Visibility of Groups and Controls in the Office 2010 Backstage View article.

huangapple
  • 本文由 发表于 2023年2月10日 06:16:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405022.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定