• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

IRibbonControl的多个窗口的上下文

用户头像
it1352
帮助1

问题说明

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

我尝试使用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

    }
}

正确答案

#1

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?

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcbcaij
系列文章
更多 icon
同类精品
更多 icon
继续加载