如何在Word JS Add-in中创建无图标的下拉命令菜单?
实现Word JS Add-in无图标下拉命令菜单
要实现仅显示文字的下拉菜单,直接移除<Icon>元素会触发Office Ribbon的默认占位图标,正确的做法是使用全透明图标替代原有图标资源,具体步骤如下:
- 制作三个尺寸的全透明PNG图片:16x16、32x32、80x80,将它们放入插件项目的资源目录(比如
assets/icons/)。 - 在manifest.xml的
<Resources>区域注册透明图标:
<bt:Images> <bt:Image id="Icon.Transparent.16x16" DefaultValue="~/assets/icons/transparent-16.png" /> <bt:Image id="Icon.Transparent.32x32" DefaultValue="~/assets/icons/transparent-32.png" /> <bt:Image id="Icon.Transparent.80x80" DefaultValue="~/assets/icons/transparent-80.png" /> </bt:Images>
- 修改Menu和Item的
<Icon>元素,指向透明图标的resid:
修改后的完整Control代码:
<Control xsi:type="Menu" id="Contoso.Menu2"> <Label resid="Contoso.Menu.Label" /> <Supertip> <Title resid="Contoso.Menu.Label" /> <Description resid="Contoso.Menu.Tooltip" /> </Supertip> <Icon> <bt:Image size="16" resid="Icon.Transparent.16x16" /> <bt:Image size="32" resid="Icon.Transparent.32x32" /> <bt:Image size="80" resid="Icon.Transparent.80x80" /> </Icon> <Items> <Item id="itemShowTaskPane2"> <Label resid="Contoso.Item1.Label"/> <Supertip> <Title resid="Contoso.Item1.Label" /> <Description resid="Contoso.Item1.Tooltip" /> </Supertip> <Icon> <bt:Image size="16" resid="Icon.Transparent.16x16" /> <bt:Image size="32" resid="Icon.Transparent.32x32" /> <bt:Image size="80" resid="Icon.Transparent.80x80" /> </Icon> <Action xsi:type="ShowTaskpane"> <TaskpaneId>ButtonId1</TaskpaneId> <SourceLocation resid="Contoso.Taskpane.Url" /> </Action> </Item> <Item id="itemExecuteFunction2"> <Label resid="Contoso.Item2.Label"/> <Supertip> <Title resid="Contoso.Item2.Label" /> <Description resid="Contoso.Item2.Tooltip" /> </Supertip> <Icon> <bt:Image size="16" resid="Icon.Transparent.16x16" /> <bt:Image size="32" resid="Icon.Transparent.32x32" /> <bt:Image size="80" resid="Icon.Transparent.80x80" /> </Icon> <Action xsi:type="ExecuteFunction"> <FunctionName>writeValue</FunctionName> </Action> </Item> </Items> </Control>
这样修改后,Ribbon上的下拉菜单和子项只会显示文字,不会有任何图标(包括损坏占位符)。
注意:如果你的插件目标是较新版本的Office(2021及以上或365订阅版),也可以尝试给<Icon>元素添加<ShowImage>false</ShowImage>属性,但该属性并非所有控件都支持,最稳妥的方式还是使用透明图标。
内容的提问来源于stack exchange,提问作者FelixKing
相关产品推荐
相关产品推荐

