如何轻松找到 WPF 视图上的“接受”按钮和“取消”按钮
我将 PRISM 应用程序设置为 MVP 模式,并通过自定义 RegionManager 显示模式窗口。我现在面临的问题是当用户使用 Alt+F4 关闭模态窗口时!视图关闭但取消按钮逻辑从未执行,这是一个错误!
因此,我需要起草一种在发出 Alt + F4 时调用视图的“取消”按钮的方法。
Alt+F4 的输入键绑定有助于我在视图中捕获事件。但问题是以一种简单的方式调用视图的取消按钮。有什么方法可以轻松地在 WPF 视图中找到“取消”和“接受”按钮吗?
任何帮助表示赞赏。谢谢!
I have my PRISM application set up on a MVP pattern and we display modal windows through custom RegionManager. The problem i face right now is when the users close the Modal Window using an Alt+F4! The View closes but the Cancel button logic is never executed, which is a bug!
So I need to draft a way to invoke the Cancel button of the view when an Alt + F4 is issued.
Having a input key binding for Alt+F4 helps me trap the event in the View. but the problem is invoking the Cancel button of the View, in a easy way. is there any way i could easily find the cancel and Accept buttons in WPF View?
Any help is appreciated. thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于关闭窗口的方法有多种(Alt+F4、关闭按钮、取消或接受按钮),因此您不应该将关闭逻辑放在按钮的代码中,因为它并不总是被处决。相反,请将关闭逻辑放入
Closing
或Closed
事件中。在“取消”按钮中,只需将DialogResult
设置为 false(在“接受”按钮中为 true),它将关闭窗口并触发Closing
和Closed
事件。Since there a several ways to close a window (Alt+F4, close button, Cancel or Accept buttons), you shouldn't put the closing logic in the code of the buttons, because it will not always be executed. Instead, put your closing logic in the
Closing
orClosed
event. In your Cancel button, just set theDialogResult
to false (true in the Accept button), it will close the window and trigger theClosing
andClosed
events.