在办公室Addin中,可以仅从功能区XML指定图像吗?
我首先从功能区设计师创建XML。我已经有一个包含按钮图像的资源文件。 我得到的行类似于
<button id="btnInsEq2" onAction="BtnInsEq2_Click" showLabel="false" />
我更改为
<button id="btnInsEq2" onAction="BtnInsEq2_Click" image="InsEquation2" showImage="true" showLabel="false" />
我的资源文件中的一些映像,该图像在运行时可以访问。我尝试了“ Intemation2”(包括文件的完整路径)上的许多变体。没有什么可用。
我看到了在代码中加载图像的答案。这真的是必要的还是我可以在XML中更简单? 顺便说一句,一条线
<button id="btnInsEq3" onAction="BtnInsEq3_Click" imageMso="Bold" label=" " showLabel="false" />
正常工作。但是我不想要 b !
I started by creating xml from the ribbon designer. I already have a resource file containing button images.
I got lines like
<button id="btnInsEq2" onAction="BtnInsEq2_Click" showLabel="false" />
which I changed to
<button id="btnInsEq2" onAction="BtnInsEq2_Click" image="InsEquation2" showImage="true" showLabel="false" />
There is some image called InsEquation2 in my resource file, which is accessible at runtime. I tried many variations on "InsEquation2" including the full path of the file. Nothing works.
I see answers where images are loaded in code. Is that really necessary or can I do it simpler in the xml?
By the way a line like
<button id="btnInsEq3" onAction="BtnInsEq3_Click" imageMso="Bold" label=" " showLabel="false" />
works fine. But I dont want B!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在功能区XML中加载图像的方法有两种。
getImage
对其支持的每个元素的回调。loadImages
customui
元素的回调。因此,如果要在功能区XML标记中指定图像名称,则需要实现
loadImages
customui
元素的回调。&lt; customui&gt;
元素的loadImage
属性使您可以指定可以加载所有图像的回调。设置此回调过程后,Office调用回调过程,并通过加载图像的每个控件的图像属性传递字符串。您无需多次实现getImage
回调,例如每次需要图像的控件的一次。例如,自定义可能包含以下标记。要提供按钮的图像,Office调用
getImage
函数。它通过参数“ mypic.jpg”,并期望返回中的ipicturedisp
对象。通过使用此技术,您可以编写一个单个回调过程,该过程返回自定义需求的所有图像,而无需编写每个单独的控件的getImage
回调。请注意,当您调用功能区的无效方法或InvalidateControl
方法时,loadImage
回调不会再次调用。对于需要在运行时动态更改图像的控件,请使用getImage
回调。There are two ways for loading images in the Ribbon XML.
getImage
callback for each element where it is supported.loadImages
callback for thecustomUI
element where all images are loaded.So, if you want to specify image names in the ribbon XML markup you need to implement the
loadImages
callback for thecustomUI
element.The
<customUI>
element'sloadImage
attribute enables you to specify a callback that can load all images. After you set up this callback procedure, Office calls the callback procedure and passes the string from the image attribute for each control that loads images. You do not need to implement thegetImage
callback multiple times, such as one time for each control that requires images. For example, a customization might include markup like the following.To supply the button's image, Office calls the
GetImage
function. It passes the parameter "mypic.jpg" and expects anIPictureDisp
object in return. By using this technique, you can write a single callback procedure that returns all the images your customization needs, without having to write each individual control'sgetImage
callback. Note that theloadImage
callback is not called again when you call the Ribbon's Invalidate method orInvalidateControl
method. For the controls that need to change images dynamically at run time, use thegetImage
callback.我将使用getImage标签,例如:
需要回调。假设您在C#中写作可能看起来像:
I would use the getImage tag like:
which requires a callback. Assuming you write in C# it could look something like:
因此,现在我发现了@eugeneastafiev建议的GetImage功能。基本上,您需要迭代资源,并找到由ImageID输入参数指示的资源。在这里,它
也需要进口系统。
用于声明和
。
EquationAcc是项目,Resources1.Resx,
如果我想知道的更好的方法,则资源文件。
So now I have found out what to put in the GetImage function suggested by @EugeneAstafiev . Basically you need to iterate through the resources and find the one indicated by the imageId input parameter. Here it is in XML / VB
Also needed Imports System.Drawing, .Collections, .Globalization, .Reflection, .Resources
for declarations and
.Diagnostics, stdole for some now unused declarations
EquationAcc is the project, Resources1.resx the resource file
If there is a better way I'd love to know.