InfoPath 2010 加载项中的事件
我目前正在尝试为 InfoPath 2010 填充器/编辑器模式实现一个简单的加载项,该加载项在“插入”功能区上添加了一些按钮,单击这些按钮会插入来自其他源的一些“模板”数据。
它工作正常,但让我烦恼的是,当用户没有选择任何字段时,它保持启用状态,而插入工具栏上的所有其他按钮以某种方式“知道”当前上下文中无法插入任何内容,因此被禁用。
关于如何与底层 XDocument 交互的 MSDN 文档已经足够了,但我正在努力弄清楚如何与编辑 UI 交互或获取信息。
这就是我想要的:
- 当用户从表单上的字段更改为字段时触发的事件
- 然后能够判断用户当前正在输入数据的类型(即富文本、纯文本等) ),因此可以根据需要启用或禁用额外的按钮。
我以为这会相当简单,但我花了将近一天的时间查看我能找到的所有内容,但一无所获!
或者我完全错过了这里的重点?
I'm currently trying to implement a simple Add-In for InfoPath 2010 Filler/Editor mode, which adds a few buttons on the "Insert" ribbon, which upon clicking inserts some "template" data from another source.
It works fine but the thing that's annoying me is that when the user has no field selected, it remains enabled while all of the other buttons on the insert toolbar somehow "know" that nothing can be inserted in the current context and are therefore disabled.
The MSDN documentation on how to interact with the underlying XDocument is perfectly adequate, but what I'm struggling to figure out is how to interact or get information from the editing UI.
This is what I'd like to have:
- An event that gets fired when the user changes from field to field on the form
- Then be able to tell what kind of field the user is currently entering data into (i.e. rich text, plain text etc), so the extra buttons can be enabled or disabled as needed.
I thought this would be fairly simple but I've spent nearly a day looking through everything I can find, and have come up empty!
Or have I completely missed the point here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几个月后我终于可以回答我自己的问题了。并不是说有人使用 InfoPath 填充程序,但以防万一有人这样做,这是我的解决方案:
我原来的问题有几个要点。
1) 当用户从一个字段更改到另一个字段时触发的事件:
这在功能区按钮 XML 中被指定为“getEnabled”属性。每次 InfoPath 认为可能需要启用或禁用该按钮时,它都会调用指定的函数。在我的实例中,我指定了: getEnabled="OnButtonGetEnabled",然后实现了一个小函数:
在我的例子中,“ribbon”是我的 Office.IRibbonUI 实例。调用“Invalidate()”非常重要,否则 InfoPath 只会调用一次。
2)如何判断用户选择的字段类型。
我仍然对我的解决方案不满意,但至少我现在有了一些可行的东西。
我编写了两个函数:
1: GetContextXPath() 调用 Globals.ThisAddIn.Application.ActiveWindow.XDocument.View.GetContextNodes(),根据结果构建 XPath 字符串(向后遍历 DOM 树)
2: HaveRichTextFieldSelected()它检查清单中指定的 XPath 是否属于“rich”类型(其 DOM 树位于Globals.ThisAddIn.Application.ActiveWindow.XDocument.Solution.DOM)
无论如何,我不会发布这里涉及的所有代码,因为它对于一个 SO 答案来说太多了,但这应该给有一些常识的人一个关于如何实施这一点。
Several months later I can finally answer my own question. Not that anyone uses InfoPath filler, but just in case anyone does, here's my solution:
There's several points to my original question.
1) Event that gets fired when the user changes from field to field:
This turns out to be specified in the Ribbon Button XML as the "getEnabled" attribute. InfoPath calls the specified function each time it thinks the button may need to be enabled or disabled. On mine I specified: getEnabled="OnButtonGetEnabled", then implemented a small function:
in my case 'ribbon' is my instance of Office.IRibbonUI. Calling 'Invalidate()' is pretty important otherwise InfoPath only ends up calling this once.
2) How to determine the type of the field the user has selected.
I'm still not happy with my solution for this but at least I now have something that works.
I've written two functions:
1: GetContextXPath() which calls Globals.ThisAddIn.Application.ActiveWindow.XDocument.View.GetContextNodes(), builds an XPath string from the result (walking backwards through the DOM tree)
2: HaveRichTextFieldSelected() which checks if the specified XPath is of type 'rich' in the manifest (whose DOM tree is under Globals.ThisAddIn.Application.ActiveWindow.XDocument.Solution.DOM)
Anyway I'm not posting all of the code involved here as it's too much for an SO answer, but this should give someone with some common sense a clue as to how to implement this.