将焦点保持在外接程序中的 WPF 组合框中

发布于 2024-09-04 04:18:36 字数 163 浏览 0 评论 0原文

我在 Word 插件中有一个组合框。组合框的内容通常足够长,可以覆盖在 Word 的缩放滑块控件上。但是,直接在缩放控件(从视图中隐藏)上选择一个项目会导致缩放控件获得焦点,关闭组合框并更改缩放设置!组合框中的选择保持不变。

如何使组合框保持焦点并将所选值更改为所选项目(在缩放栏上)?谢谢...

I have a combobox in a Word addin. The contents of the combobox are often long enough to drape over Word's Zoom slider-bar control. However, selecting an item directly over the zoom control (which is hidden from view) causes the zoom control to get focus, close the combobox, and change your zoom setting! The selection in the combobox is untouched.

How can I make the combo box keep focus and change the selected value to the item (over the zoom bar) selected? Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强者自强 2024-09-11 04:18:36

我在 WPF 中遇到了同样的问题,看起来它与 Word 处理子窗口事件的方式有关。每当在 Word 窗口之一上绘制下拉列表(或者可能是任何其他“弹出”控件,如上下文菜单)时,它就会变得有点贪婪,并假设您正在单击底层窗口。

我不太了解消息/事件在 Windows 中的工作原理,也没有时间找出解决问题的最佳方法,但根据某处有关创建无边框窗口的帖子,我尝试修改窗口样式WinForms 用户控件如下(windows 样式常量来自 http:// www.pinvoke.net/default.aspx/Constants/Window%20styles.html):

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams p = base.CreateParams;
            if (!DesignMode)
            {
                unchecked
                {
                    p.Style = (int)(WindowStyles.WS_VISIBLE |
                                    WindowStyles.WS_POPUP |
                                    WindowStyles.WS_CLIPSIBLINGS |
                                    WindowStyles.WS_CLIPCHILDREN);
                }
            }
            return p;
        }
    } 

奇怪的是(或者对于更熟悉 Windows 消息的人来说可能不那么好奇),下拉菜单确实响应键盘事件(例如单击弹出列表,然后使用键盘选择项目)。

从功能上讲,上面的代码似乎没有问题......但我不确定说用户控件是弹出窗口而不是子控件会产生什么后果。

与此相关的另一篇文章是 WPF ComboBox does在任务窗格中使用时不要保持打开状态

I've run into this same issue with WPF, and it looks like it has something to do with the way Word is handling events from child windows. Whenever the dropdown list (or probably any other "popup" control like a context menu) is drawn over one of Word's windows, it gets a bit greedy and assumes you're clicking on the underlying window.

I don't know a whole lot about how messaging/events works in Windows and I haven't had time to figure out the best way to address the problem, but based on a post somewhere about creating borderless windows I tried modifying the window styles of the WinForms user control as follows (windows style constants from http://www.pinvoke.net/default.aspx/Constants/Window%20styles.html):

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams p = base.CreateParams;
            if (!DesignMode)
            {
                unchecked
                {
                    p.Style = (int)(WindowStyles.WS_VISIBLE |
                                    WindowStyles.WS_POPUP |
                                    WindowStyles.WS_CLIPSIBLINGS |
                                    WindowStyles.WS_CLIPCHILDREN);
                }
            }
            return p;
        }
    } 

Curiously (or maybe not so curiously for people that are more familiar with Windows messages), the dropdown DOES respond to keyboard events (e.g. click to pop up the list, then use the keyboard to select an item).

Functionally there doesn't seem to be a problem with the above code...but I'm not sure what the ramifications are of saying the user control is a popup instead of a child.

Another post that relates to this is WPF ComboBox doesn't stay open when used in a Task Pane.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文