带有单击事件处理程序的 WPF 命令
当我在 Button
控件中使用 Command
时,与 Click
事件连接的事件处理程序永远不会引发,
我如何使用 命令
并处理Click
事件处理程序?
When I use the Command
in a Button
control the event handler which joined with Click
event will never raised,
How can I use the Command
and handle the Click
event handler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 ICommand 附加到另一个属性并从 Click 处理程序中执行它。
在处理程序中:
如果您想保留命令禁用行为,您还需要做一些额外的工作。
You could attach the ICommand to another property and execute it from the Click handler.
and in the handler:
You'd also need to do some extra work if you wanted to keep the Command disabling behavior.
您需要 MVVMLight 中的 EventToCommand 行为
You need the EventToCommand behaviour in MVVMLight
命令是一种周事件。命令的好处是您不需要使用事件。实际上,如果您使用 Viewmodel 模式,则根本不需要使用隐藏代码和事件。请参阅中继命令: http: //blog.galasoft.ch/archive/2009/09/26/using-relaycommands-in-silverlight-and-wpf.aspx
A command is a kind of week event. The good thinks about commands is that you do not need to use events. Actually you do not need to use code behind at all and events if you use a Viewmodel pattern. See relay commands: http://blog.galasoft.ch/archive/2009/09/26/using-relaycommands-in-silverlight-and-wpf.aspx