我在excel的上下文菜单上有一个CommandBarPopup,其中包含三个CommandBarButtons,其中一个按钮打开网页,另外两个按钮打开自定义任务窗格。
如果我使包含承载WPF用户控件的元素宿主的自定义任务窗格可见,则我添加的任何CommandBarButtons将停止工作。即使我关闭了自定义任务窗格,它仍然无法工作。
如果我对自定义任务窗格容器和web浏览器执行同样的操作,它似乎工作得很好。
下面是我们使用的代码
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);
}发布于 2013-03-13 23:02:42
因此,答案是CommandBarButtons在变量作用域结束后被释放,这令人惊讶,因为我假设它们会附加到excel应用程序对象上。再看看excel命令栏,我可以看到那里的按钮,但点击它们会导致点击事件不被触发。无论如何,我将它们存储在一个类变量中,它再次工作。
https://stackoverflow.com/questions/15162040
复制相似问题