按钮单击WPF中的事件 [英] Button Click Event in WPF

查看:107
本文介绍了按钮单击WPF中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为保存按钮编写点击事件。但是,当我在xaml中写入时,对我来说没有OnClick功能或Click功能。



那么,怎样才能为按钮写一个事件来执行某些操作?

I'm trying to write an click event for save button. However, when I write in xaml, there is no OnClick function or Click function for me.

So, how can write an event for the button to perform some action?

推荐答案

<button content="Save" height="27" width="50" click="Button_Click" />





在XAML中,事件是单击而非OnClick,因为它在Windows窗体中。



In XAML the event is "Click" not "OnClick" as it was in windows forms.


您应该学习MVVM。似乎save应该是ViewModel的一部分,而不是View的一部分。在这种情况下,您可以使用类型ICommand将Command绑定到ViewModel中的属性。我已经使用WPF完成了一些项目,但没有使用MVVM,并且发现它是一个错误。维护MVVM模式比处理直接处理事件容易得多。
You should learn MVVM. It would seem that save should be part of the ViewModel, not part of the View. In this case you would bind a Command to a property in the ViewModel with a type of ICommand. I have done some projects using WPF, but not MVVM, and have found that it is a mistake. Much easier to maintain the MVVM pattern than to deal with directly handling events.


这篇关于按钮单击WPF中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆