简体   繁体   English

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

[英]WPF- How can I stop a popup in a control template from closing when clicked?

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? 我已经看到了一个问题: 为什么单击WPF弹出窗口的背景区域时会关闭它?

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. 但是该命令不会触发。

尝试使用PreviewMouseLeftButtonDown事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WPF-我可以在不使用模板触发 IsMouseOver 时更改 MenuItem 和 SubMenuItem 的背景颜色吗? - WPF- Can I Change Background Color of MenuItem and SubMenuItem When IsMouseOver Triggered Without Using Template? WPF-如何显示图像源的裁剪区域 <Image> 控制? - WPF- How Can I Show a Cropped Region of an ImageSource in an <Image> Control? WPF-如何绑定两个Listbox的SelectedValue属性? - WPF- How can I bind to SelectedValue properties of two Listboxes? Wpf-如何在代码中获取普通 TextBox 的 LineHeight? - Wpf- How can I get the LineHeight of a normal TextBox in code? WPF 弹出控件正在立即关闭 - WPF popup control is closing immediately 在WPF中如何控制是否单击了另一个按钮 - In WPF how can I control whether another button clicked 当我在文本框内单击时如何在 wpf 中启用弹出控件? - How to enable a popup control in wpf when I click inside a textbox? WPF-如何使菜单控件看起来很自然 - WPF- How to Make Menu control look native WPF-如何重构多个 ListViewItem 样式模板而更改很少? - WPF- How to refactor multiple ListViewItem Style Template with few changes? 如何在单击另一个控件时打开 WPF 弹出窗口,仅使用 XAML 标记? - How to open a WPF Popup when another control is clicked, using XAML markup only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM