WPF ComboBox在任务窗格中使用时不会保持打开状态 [英] WPF ComboBox doesn't stay open when used in a Task Pane

查看:167
本文介绍了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在任务窗格中使用时不会保持打开状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆