【问题标题】:CommandBarButton on Context Menu doesn't work after ElementHost becomes visibleElementHost 变得可见后,上下文菜单上的 CommandBarButton 不起作用
【发布时间】:2013-03-01 16:13:32
【问题描述】:

我在 Excel 的上下文菜单中有一个 CommandBarPopup,其中包含三个 CommandBarButtons,其中一个按钮打开网页,另外两个打开自定义任务窗格。

如果我使包含托管 WPF 用户控件的元素宿主的自定义任务窗格可见,那么我添加的任何 CommandBarButtons 都将停止工作。 即使我关闭了自定义任务窗格,它仍然无法正常工作。

如果我对自定义任务窗格容器和网络浏览器执行相同操作,它似乎可以正常工作。

这是我们正在使用的代码

private void InitializeComponent()
    {
        this.elementHost1 = new System.Windows.Forms.Integration.ElementHost();
        this.myView = new MyView();
        this.SuspendLayout();
        // 
        // elementHost1
        // 
        this.elementHost1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.elementHost1.Location = new System.Drawing.Point(0, 0);
        this.elementHost1.Name = "elementHost1";
        this.elementHost1.Size = new System.Drawing.Size(780, 560);
        this.elementHost1.TabIndex = 0;
        this.elementHost1.Text = "elementHost1";
        this.elementHost1.Child = this.myView;
        // 
        // MyTaskPane
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Controls.Add(this.elementHost1);
        this.Name = "MyTaskPane";
        this.Size = new System.Drawing.Size(780, 560);
        this.ResumeLayout(false);

    }

【问题讨论】:

  • 投票结束这个问题的人想要解释为什么?

标签: excel wpf-controls vsto excel-2010 excel-addins


【解决方案1】:

所以答案是,一旦变量范围结束,就会释放 CommandBarButtons,这令人惊讶,因为我认为它们会附加到 excel 应用程序对象。还查看了 excel 命令栏,我可以看到那里的按钮,但是单击它们会导致单击事件未触发。 无论如何,我将它们存储在一个类变量中,它又可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-03
    相关资源
    最近更新 更多