如何获取 Ribbon 控件类上的自定义任务窗格对象
开发 Excel vsto 项目,我如何处理功能区控件类中的自定义任务窗格。 例如,我想在单击功能区控件的按钮时显示自定义任务窗格。
朵拉
Developing a Excel vsto project, how could I handle the Custom Task Pane in the Class which is a Ribbon Control.
For example, I would like to show the Custom Task Pane when I click the button of the Ribbon Control.
Dora
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您正在使用 Excel VSTO 加载项和功能区可视化设计器。您可以通过加载项上的属性访问自定义任务窗格来实现您想要的目的:
...并在功能区中添加按钮,并为单击事件添加事件处理程序,通过全局访问加载项:
我不久前写了一篇文章 描述了过程,你可能会发现它很有用。
使用 xml 功能区这也是可行的。
I assume you are working with an Excel VSTO add-in, with the Ribbon Visual Designer. You can achieve what you want by making your custom Task Pane accessible via a property on your Add-In:
... and adding a button in your Ribbon, and adding an event handler for the click event, accessing the add-in via Globals:
I wrote a post a while back which describes the process, you may find it useful.
This is also feasible using the xml ribbon.
这可以通过拥有 Win Forms 用户控件来完成。
我曾参与过一个项目,其中我们必须扩展 MS Word 并需要此功能,但相同的示例也适用于 Excel。
我在网上偶然发现的另一个有趣的方法是拥有一个 Windows 用户控件并在 Windows 控件中托管一个 WPF 用户控件!
这当然可以让您利用 WPF 提供的所有出色工具,下面是一个示例:
1)在功能区上放置一个切换按钮(可视化设计器)。这将用于显示隐藏任务窗格。
使用 ToggleButton 是一个不错的选择,因为按下时它会突出显示。
2) 将以下代码添加到 ToggleButton 的单击事件
3) 将项目中的引用添加到以下程序集 - WindowsFormsIntegration
4) 在 ThisAddIn.cs 中添加下面列出的两个 using 指令:
5)添加两个用户控件
5.1)用户控件(名称 - taskPaneControl1)
5.2)用户控件(WPF),(名称 - con)
使用我使用过的名称会有所帮助复制/粘贴下面的代码,但如果您愿意,可以通过任何方式更改它
6) 将下面的代码添加到 ThisAddIn.cs 类
6) 将下面的两个代码添加到 中的启动事件ThisAddIn.cs
当打开 MS Office 应用程序时,任务窗格将被隐藏,切换可见属性以在启动事件中更改此设置。
导航到 ToggleButton 并按几次以确保任务窗格按预期显示
另请查看以下链接 我的大部分代码都来自这里 - http://xamlcoder.com/cs/blogs/joe/archive/2007/07/17/using-wpf-with-vsto-office-2007.aspx
This can be accomplished by having a Win Forms user control.
I've worked on a project where we had to extend MS Word and needed this functionality, but the same example will apply to Excel.
Another interesting way I stumbled upon on the net is to have a Windows user control and host a WPF user control within the Windows control!
This ofcourse allows you to take advantage of all the awesome tools you get with WPF, here is an example:
1)Drop a ToggleButton on a Ribbon(Visual Designer).This will be used to show hide the task pane.
Using ToggleButton is a good choice as it appears highlighted when pressed down.
2)Add below code to the click event of the ToggleButton
3)Add a reference from your project to the following assembly - WindowsFormsIntegration
4)In your ThisAddIn.cs add the two using directives listed below:
5)Add two user controls
5.1)User control (name - taskPaneControl1)
5.2)User control(WPF),(name - con)
Using the names I've used will help when copying/pasting the code below but by any means change it if you wish to
6)Add below code to the ThisAddIn.cs class
6)Add the two code below to the Startup event in your ThisAddIn.cs
When an MS Office Application is opened the task pane will be hidden toggle the Visible property to change this in the Startup event.
Navigate to the ToggleButton and press it a few times to make sure the task pane is showing as expected
Also have a look at the following link most of my code came from here - http://xamlcoder.com/cs/blogs/joe/archive/2007/07/17/using-wpf-with-vsto-office-2007.aspx
这是一个艰巨的挑战,因为功能区和任务窗格是独立的实体。主要挑战之一是每个检查器只有一个 Ribbon 类实例和多个任务窗格实例。为此,需要对 Office 内部结构有一定的深入了解。
该解决方案还取决于您使用的是功能区 XML 还是功能区设计器。您使用哪种方法?
This is a difficult challenge since the Ribbon and Task Panes are separate entities. One of the main challenges is that there is only one instance of the Ribbon class and multiple instances of the task pane for each inspector. To this properly requires some advanced understanding of the Office internals.
The solution also depends on whether you are using the Ribbon XML or Ribbon Designer. Which approach are you using?