首页 > 编程知识 正文

英文字母c的发音,做c

时间:2023-05-04 10:29:23 阅读:149884 作者:2980

1、定义MVVM是模型视图模型的缩写。 那本质上是MVC的改良版。 所谓MVM,就是抽象其中的View的状态和行为,试着将视图UI和业务逻辑分开。

用于存储数据的m :模型(模型)数据模型

v:view(UI界面) )

VM :视图(视图模式)

2、设计简单的MVVM模型2.1基类(继承INotifyPropertyChanged )。 允许在数据属性发生变化时同步显示UI界面

classnotificationobject : inotifypropertychanged { publiceventpropertychangedeventhandlerpropertychanged; //属性更改的事件处理程序publicvoidrasiepropertychanged (string property name ) if ) propertychanged!=null(//如果事件处理程序不为null,则将其本身作为事件源,输入this.property changed.invoke (this、 newpropertychangedeventargs )发送事件数据以通知propertychangedeventargs )已更改} } } 2.2命令属性(Command )命令属性在手臂上是委托的,在手臂上是委托的

classdelegatecommand 3360 I command { publiceventeventhandlercanexecutechanged; publicboolcanexecute (object parameter ) if ) this.canexecutefunc==null { return true; } else return this.canexecutefunc (parameter ); } public void execute (对象参数) if ) executeaction==null ) { return; }this.executeaction(parameter ); } publicactionobjectexecuteaction { get; set; } public Funcobject,bool CanExecuteFunc { get; set; } } 2.3 ViewModel设计设计了一个简单的加法,分析可以知道有三个数据属性(两个输入,一个结果)和一个命令属性

///summary ///表单的ViewModel (数据属性、命令属性)//summaryclassmainwindowviewmodels 3360 notification object (# region数据属性poraties } set { input1=value; this.rasiepropertychanged (' input1' ); } } private double input2; publicdoubleinput2{ get { return input 2; } set { input2=value; this.rasiepropertychanged (' input2); } } private double result; publicdoubleresult { get }返回结果; } set { result=value; this.rasiepropertychanged (' result ); }#endregion//summary//创建添加指令属性(本质委托)//summarypublicdelegatecommandaddcommand { get; set; } privatevoidadd (object parameter ) this.result=this.input2this.input 1; } public MainWindowViewModels () this.add command=newdelegatecommand ); this.add command.execute action=newactionobject (this.add; } } 2.4 View绑定viewmodel gridx : name=' grid1' grid.rowdefinitionsrowdefinitionheight=' auto '/rowdefinitionheight=rowdefinitionheight=' * '//grid.rowdefinitionstextboxx : name=' txtbox1' grid.row='0' margin='5' backgron textboxx : name=' txtbox2' grid.row='1' margin='5' back ground=' bisque ' text=' { binding input2} '/textboxx : name=' txtbox3' grid.row='2' margin='5' back ground=' bisque ' text=' { binding result } '/butttotttttttttttton

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。