Skip to content

请教一个WPF 中Popup的技术问题,可能是遇到微软的Bug了。 #1

Description

@kwonganding

来自:WPF教学|深度解析基于ResourceDictionary的WPF动态主题框架架构|DynamicTheme | 内附源码

非常感谢回复,这个bug困扰了我好几天,也研究了各种方法,有的能绕过,但都不优雅。

需求场景很简单:用一个Popup(粉色的那个区域)来实现快捷输入,点击Popup外的任意地方,Popup自动关闭,如下图。
image

  • 用按钮Click事件打开Popup,一切正常,符合预期。
  • 在输入框的双击事件中打开Popup,就有问题了。
    • 双击输入框,打开Popup,点击Popup外的任意地方,Popup没有关闭。,包括拖动窗口、调整窗口大小,Popup都不会关闭。
    • 如果点击一下Popup中的输入框,再次点击Popup外的任意地方,Popup会正常关闭。

在一篇文章(也是一位微软MVP)中有提到Popup存在的问题:https://blog.walterlv.com/post/how-to-open-a-wpf-popup.html

通过google/chatgpt/stackoverflow 都没找到比较理想的解决方法解决。

代码文件PopupBug.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions