IRibbonControl的多个窗口的上下文 [英] IRibbonControl's context for multiple windows

查看:105
本文介绍了IRibbonControl的多个窗口的上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个示例后台扩展。我需要从相应的演示文稿中获取一些信息并显示该信息。

我尝试使用IRibbonControl的Context对象,但它从后台返回控件的ActiveWindow。

I created a sample backstage extention. I need to get some info from the corresponding presentation and display that info.
I tried to use Context object of IRibbonControl, but it returns ActiveWindow for controls from both backstages.

创建2个演示文稿:"演示文稿1"和"演示2",后台开放 - >两个窗口中的自定义选项卡单击任何按钮。两个按钮都有相同的文字。



所以问题:是否有任何方法可以获得后台控制的相应窗口。

Create 2 presentations: "Presentation 1" and "Presentation 2", open backstage -> Custom Tab in both windows. Click any button. Same text will be in both buttons.

So the question: is there any way to get a corresponding window for the backstage control.

请参阅下面的自定义ui和代码。

See custom ui and code below.

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <backstage>
    <tab id="tabAccount" label="Custom Tab" title="Custom Tab">
      <firstColumn>
        <taskFormGroup id="customTaskFormGroup">
          <category id="customCategory">
            <task id="customTask" label="Custom Task">
              <group id="customGroup" showLabel="true">
                <primaryItem>
                  <button id="testButton" getLabel="GetLabel" onAction="DoAction" />
                </primaryItem>
              </group>
            </task>
          </category>
        </taskFormGroup>
      </firstColumn>
    </tab>
  </backstage>
</customUI>





namespace PowerPointContext
{
    [ComVisible(true)]
    public class CustomBackstage : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;

        public string GetCustomUI(string ribbonID)
        {
            var customUI = GetResourceText("PowerPointContext.CustomBackstage.xml");
            return customUI;
        }

        public void Ribbon_Load(Office.IRibbonUI ribbonUI)
        {
            this.ribbon = ribbonUI;
        }

        public String GetLabel(Office.IRibbonControl control)
        {
            return "Active Presentation: " + (control.Context as DocumentWindow).Caption;
        }

        public void DoAction(Office.IRibbonControl control)
        {
            ribbon.InvalidateControl("testButton");
        }

        #region Helpers

        private static string GetResourceText(string resourceName)
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            string[] resourceNames = asm.GetManifestResourceNames();
            for (int i = 0; i < resourceNames.Length; ++i)
            {
                if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                {
                    using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                    {
                        if (resourceReader != null)
                        {
                            return resourceReader.ReadToEnd();
                        }
                    }
                }
            }
            return null;
        }

        /// <summary>
        /// Converts the slide to image.
        /// </summary>
        /// <returns></returns>
        private String ConvertSlideToImage(PowerPoint.Slide slide)
        {
            if (slide != null)
            {
                var tempFileName = System.IO.Path.GetTempFileName();
                slide.Export(tempFileName, "JPG");
                return tempFileName;
            }
            return "";
        }

        #endregion

    }
}

推荐答案

Hello Andrey,

Hello Andrey,

当前论坛适用于Office 2013 Apps,而非COM加载项。这就是为什么我建议在
中提出这样的问题。
一般办公室开发 
论坛代替。

The current forum is for Office 2013 Apps, not COM add-ins. That's why I'd recommend asking such questions in the General Office Development  forums instead.

我刚检查了
上下文
属性。我始终为打开的每个演示文稿获取正确的标题值。您在PC上安装了什么版本和内部版本的PowerPoint?

I have just checked the Context property in PowerPoint 2013. I always get the correct caption value for each presentation opened. What version and build number of PowerPoint do you have installed on the PC?

您是否尝试调试代码?
Id
属性返回?

Did you try to debug the code? What value does the Id property returns?


这篇关于IRibbonControl的多个窗口的上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆