WPF 矩形没有 Click 事件
似乎 WPF 矩形 形状没有定义了 Click 事件。 我应该用什么来代替?
它确实有 MouseUp,但行为并不完全相同。
It seems that the WPF Rectangle shape does not have the Click event defined. What am I supposed to use instead?
It does have MouseUp, but it's not quite the same behavior.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您对
MouseDown
和MouseUp
不满意,也许您可以将Rectangle
放入Button
中,然后处理Button
的Click
事件?这实际上取决于您所追求的行为。 如果需要请详细说明。
If you're not happy with
MouseDown
andMouseUp
, perhaps you could just put theRectangle
in aButton
and handle theButton
'sClick
event?It really depends with the behavior you're after. Please elaborate if needs be.
要将点击处理添加到矩形本身,您可以使用 InputBindings 属性:
这将导致在单击矩形时执行 FooCommand。 如果您使用 MVVM,这会很方便!
To add click handing to a Rectangle itself, you can use the InputBindings property:
This will cause the FooCommand to be executed when the rectangle is clicked. Handy if you're using MVVM!
我正在寻找相关的 DoubleClick 事件,并发现 此建议只是将感兴趣的对象嵌入到 ContentControl 中。
这是他们的示例(带有边框,也不支持单击/双击)。
I was looking for the related DoubleClick event and came across this suggestion to simply embed the object of interest in a ContentControl.
Here is their example (with a border, which also did not support click/double click).
矩形有事件 Tapped,效果很好。 在为 Windows 8.1 设计通用应用程序时,出现了一些新事件。 轻敲、双敲击、右敲击和固定。
Rectangle has event Tapped, which works fine. In designing universal apps for Windows 8.1, there are new events. Tapped, DoubleTaped, RightTapped and Holding.