gpt4 book ai didi

vsto - 如何同时拥有 VSTO 功能区和上下文菜单?

转载 作者:行者123 更新时间:2023-12-01 22:29:29 25 4
gpt4 key购买 nike

编辑:海报的答案是正确的,但包含内容应为 xmlns="http://schemas.microsoft.com/office/2009/07/customui"。作为副作用,XML 文件中定义的功能区和上下文菜单在 Office 2007 中不起作用。如果您需要在 2007 中添加上下文菜单,请使用现已弃用的菜单,并且 Outlook 2007 消息窗口中的上下文菜单是不可能的.

this.Application.ItemContextMenuDisplay += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(Application_ItemContextMenuDisplay);

我创建了功能区和上下文菜单,但我不知道如何同时部署它们。

我的功能区 XML 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>

<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui">

<ribbon>

<tabs>

<tab id="testTab" label="Test Label">

<group id="testGroup" label="test">

<button id="testButton" onAction="testAction" label="Test" size="large"

getImage ="GetCustomImage" screentip="Test Ribbon Functionality."/>

</group>

</tab>

</tabs>

</ribbon>

</customUI>

Ribbon.cs 有

public string GetCustomUI(string ribbonID)

{

String ui = null;

// Examine the ribbonID to see if the current item

// is a Mail inspector.

if (ribbonID == "Microsoft.Outlook.Mail.Read" ||

ribbonID == "Microsoft.Outlook.Mail.Compose")

{

// Retrieve the customized Ribbon XML.

ui = GetResourceText("WDCrypt2.Ribbon.xml") ;



}

return ui;

}

ContextMenu XML 看起来像(来自教程)

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

<contextMenus>

<contextMenu idMso="ContextMenuText">

<button idMso="FontDialog" visible="false" />

<toggleButton id="MyToggle" label="My Toggle Button" />

<button id="MyButton" label="My Button" insertBeforeMso="HyperlinkInsert" onAction="GetButtonID" />

<menuSeparator id="MySeparator" />

<menu id="MySubMenu" label="My Submenu" >

<button id="MyButton2" label="Button on submenu" />

</menu>

<gallery id="galleryOne" label="My Gallery">

<item id="item1" imageMso="HappyFace" />

<item id="item2" imageMso="HappyFace" />

<item id="item3" imageMso="HappyFace" />

<item id="item4" imageMso="HappyFace" />

</gallery>

<dynamicMenu id="MyDynamicMenu" label= "My Dynamic Menu" getContent="GetMyContent" />

</contextMenu>

</contextMenus>

</customUI>

其 cs 文件如下所示:

private Office.IRibbonUI ribbon;

public Ribbon2()
{
}

#region IRibbonExtensibility Members

public string GetCustomUI(string ribbonID)
{
return GetResourceText("WDCrypt2.Ribbon2.xml");
}

问题是在我的插件类中使用我必须:

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{

return new Ribbon();

}

或者

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{

return new Ribbon2(); //The Context Menu

}

但我不能两者兼得。如何同时获取上下文菜单和功能区?

编辑: 我也想避免使用 Application.ItemContextMenuDisplay,因为 API 已正式弃用此功能。

最佳答案

您需要合并两个功能区 XML 文件,然后得到一个回调文件:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab id="testTab" label="Test Label">
<group id="testGroup" label="test">
<button id="testButton" onAction="testAction" label="Test" size="large"
getImage ="GetCustomImage" screentip="Test Ribbon Functionality."/>
</group>
</tab>
</tabs>
</ribbon>
<contextMenus>
<contextMenu idMso="ContextMenuText">
<button idMso="FontDialog" visible="false" />
<toggleButton id="MyToggle" label="My Toggle Button" />
<button id="MyButton" label="My Button" insertBeforeMso="HyperlinkInsert" onAction="GetButtonID" />
<menuSeparator id="MySeparator" />
<menu id="MySubMenu" label="My Submenu" >
<button id="MyButton2" label="Button on submenu" />
</menu>
<gallery id="galleryOne" label="My Gallery">
<item id="item1" imageMso="HappyFace" />
<item id="item2" imageMso="HappyFace" />
<item id="item3" imageMso="HappyFace" />
<item id="item4" imageMso="HappyFace" />
</gallery>
<dynamicMenu id="MyDynamicMenu" label= "My Dynamic Menu" getContent="GetMyContent" />
</contextMenu>
</contextMenus>
</customUI>

关于vsto - 如何同时拥有 VSTO 功能区和上下文菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6652837/

25 4 0