About the application of lambda and relayCommand
2017-09-04 09:14
513 查看
public RelayCommand<TextEditor> SaveCommand
{
get
{
?? 代表这个返回的_saveCommand为false时,就new一个新对象返回。
return _saveCommand
?? (_saveCommand = new RelayCommand<TextEditor>(
editor =>
{
try
{
// Can't add Encoding when save, it's wired, but it's the fact. Otherwise some wired character will appear at the beginning of line 1
File.WriteAllText(Case.CasePath, editor.Text);
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
return;
}
MessageBox.Show("Case " + Case.CaseName + " saved.");
}, (x) => !this.CaseIsRunning));
}
}
editor => 和(x) =>这两个lambda函数作为参数在RelayCommand的构造函数中。
如_saveCommand=new RelayCommand<TextEditor>(void A{},bool B{});当B为真时,A函数才执行。
这种语法是在RelayCommand的构造函数中定义的,A是excute()方法,后面是CanExcute()后者返回一个bool类型,当返回值为ture是excute才会执行。
{
get
{
?? 代表这个返回的_saveCommand为false时,就new一个新对象返回。
return _saveCommand
?? (_saveCommand = new RelayCommand<TextEditor>(
editor =>
{
try
{
// Can't add Encoding when save, it's wired, but it's the fact. Otherwise some wired character will appear at the beginning of line 1
File.WriteAllText(Case.CasePath, editor.Text);
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
return;
}
MessageBox.Show("Case " + Case.CaseName + " saved.");
}, (x) => !this.CaseIsRunning));
}
}
editor => 和(x) =>这两个lambda函数作为参数在RelayCommand的构造函数中。
如_saveCommand=new RelayCommand<TextEditor>(void A{},bool B{});当B为真时,A函数才执行。
这种语法是在RelayCommand的构造函数中定义的,A是excute()方法,后面是CanExcute()后者返回一个bool类型,当返回值为ture是excute才会执行。
相关文章推荐
- Application Field and Fetures of the Spiral Classifier
- The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2
- 1.4 Dynamically change the look of an application by using view states,transitions and effects
- the diary for one command application of pipe in Linux
- About the Usage of fseek and ftell
- 解决方案: the selected file is a solution file but was created by a newer version of this application and cannot be opened
- Discover the ins and outs of J2EE application assembly and deployment
- About:How to write the declaration of pointers and references rightly.
- Meandering Through the Maze of MFC Message and Command Routing MFC消息路由机制分析
- Get and display the size of file and directory in Linux system using du command 获取和现实linux文件大小(三)
- Information About The Space of MFC and C#,ASP.NET
- The Details About Syntax of gcc as and ld
- About the Height and Width property of DisplayObject
- All about TAF - 10g&11g :Configuration of TAF(Transparent Application Failover) and Load Balancing
- Windows Phone 8: Evolution of the Runtime and Application Compatibility
- Know more about the organization of solution and project
- About the Height and Width property of DisplayObject
- The Usage of Lambda and Heap in the C++ STL
- [转]Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application (3 of 10)
- About the issue of After delete a record from grid and refresh the datasource, the cursor go to first top record.