WPF ComboBox在任务窗格中使用时不会保持打开状态

编程入门 行业动态 更新时间:2024-10-25 06:24:22
本文介绍了WPF ComboBox在任务窗格中使用时不会保持打开状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个与WPF Interop和Excel Addin有一个奇怪的bug。我正在使用.Net 3.5 SP1。

我正在使用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标志,那么组合框和其他弹出窗口按预期工作。

他们给了我这段代码添加到我的ADXExcelTask​​Pane:

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在任务窗格中使用时不会保持打开状态

本文发布于:2023-11-12 01:34:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580137.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗格   状态   WPF   ComboBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!