WPF-如何阻止控件模板中的弹出窗口在单击时关闭?

发布于 2024-09-14 07:19:32 字数 1034 浏览 2 评论 0原文

控件模板用于自定义控件。

我见过这个问题: 为什么 WPF 弹出窗口在其关闭时关闭背景区域被单击?

但是我不知道如何将命令绑定到控件模板中的事件。我尝试了这个:

<Popup 
                        Name="Popup"
                        Placement="Bottom"
                        IsOpen="{TemplateBinding IsDropDownOpen}"
                        AllowsTransparency="True" 
                        Focusable="True"
                        PopupAnimation="Slide"
                        >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseLeftButtonDown">
                                <GalaSoft_MvvmLight_Command:EventToCommand Command="{TemplateBinding PopupClickedCommand}" PassEventArgsToCommand="True"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Popup>

但是命令没有触发。

The control template is for a custom control.

I have seen this question:
Why does a WPF Popup close when its background area is clicked?

However I could not figure out how to bind a command to an event in the control template. I tried this:

<Popup 
                        Name="Popup"
                        Placement="Bottom"
                        IsOpen="{TemplateBinding IsDropDownOpen}"
                        AllowsTransparency="True" 
                        Focusable="True"
                        PopupAnimation="Slide"
                        >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseLeftButtonDown">
                                <GalaSoft_MvvmLight_Command:EventToCommand Command="{TemplateBinding PopupClickedCommand}" PassEventArgsToCommand="True"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Popup>

But the command does not fire.

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

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

发布评论

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

评论(1

守护在此方 2024-09-21 07:19:32

尝试 PreviewMouseLeftButtonDown 事件。

Try the PreviewMouseLeftButtonDown event.

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