我正在使用Add-in Express为Excel 2003创建自定义任务窗格。在该任务窗格中,我使用ElementHost托管一个WPF UserControl。 UserControl只包含一个带有TextBox和ComboBox的Grid。我的问题是,一切都正常显示,ComboBox不会保持下拉,除非我按住鼠标向下箭头。
我不相信这一定与Add-in Express相关,因为我在Excel中无模式地显示WPF窗口时遇到类似的问题。
第二个问题是ComboBox似乎不情愿放弃焦点。如果我点击它,文本区域将变为灰色,表示它具有焦点,但我无法将焦点移动到窗口中的其他位置。唯一的办法就是移动鼠标滚轮。
其他人也有类似的问题,并设法解决它?
解决方案Add-in Express为我查看了这一点,结果是与添加到Excel的任务窗格的Window样式有关。如果您关闭Windows CreateParams中的WS_CHILD标志,那么组合框和其他弹出窗口按预期工作。
他们给了我这段代码添加到我的ADXExcelTaskPane:
private const uint WS_CHILD = 0x40000000; private const uint WS_CLIPCHILDREN = 0x02000000; private const uint WS_CLIPSIBLINGS = 0x04000000; private CreateParams _CreateParams = new CreateParams(); protected override CreateParams CreateParams { get { _CreateParams = base.CreateParams; if(!DesignMode) _CreateParams.Style =(int)(WS_CLIPCHILDREN | WS_CLIPSIBLINGS); // | WS_CHILD return _CreateParams; } }
I have a strange bug with WPF Interop and an Excel Addin. I'm using .Net 3.5 SP1.
I'm using Add-in Express to create a Custom Task Pane for Excel 2003. Within that taskpane I'm using ElementHost to host a WPF UserControl. The UserControl simply contains a Grid with a TextBox and ComboBox. My problem is that whilst everything displays properly, the ComboBox won't stay dropped-down unless I hold the mouse down over the down-arrow.
I don't believe this is necessarily related to Add-in Express because I've had a similar problem when I tried displaying a WPF window modelessly in Excel.
A second problem is that the ComboBox seems reluctant to give up focus. If I click it, the text area goes grey to indicate that it has focus, but I can't move focus anywhere else in the window. The only way to wrest focus away is to move the mousewheel.
Anybody else had a similar problem, and managed to fix it?
解决方案Add-in Express looked into this for me, and it turns out to have something to do with the Window style of the Task Pane that gets added to Excel. If you turn off the WS_CHILD flag in the Windows CreateParams then Combo Boxes and other popups work as expected.
They gave me this snippet of code to add to my ADXExcelTaskPane:
private const uint WS_CHILD = 0x40000000; private const uint WS_CLIPCHILDREN = 0x02000000; private const uint WS_CLIPSIBLINGS = 0x04000000; private CreateParams _CreateParams = new CreateParams(); protected override CreateParams CreateParams { get { _CreateParams = base.CreateParams; if (!DesignMode) _CreateParams.Style = (int)(WS_CLIPCHILDREN | WS_CLIPSIBLINGS); //| WS_CHILD return _CreateParams; } }
更多推荐
WPF ComboBox在任务窗格中使用时不会保持打开状态
发布评论