by Laurent Bugnion via Silverlight on 6/15/2011 2:39:30 PM
In MVVM Light V4, I am proposing a new RelayCommand snippet, making it easier to declare and initialize a RelayCommand. I came up with a syntax that allows having the RelayCommand and its initialization in one convenient location.
I am looking for feedback, so leave your comments below!!
This is the code created by the code snippet after expansion, for a simple RelayCommand.
private RelayCommand _testCommand; /// <summary> /// Gets the TestCommand. /// </summary> public RelayCommand TestCommand { get { return _testCommand ?? (_testCommand = new RelayCommand( () => { // Execute delegate throw new NotImplementedException(); }, () => { // CanExecute delegate throw new NotImplementedException(); })); } }
This is the code created by the code snippet after expansion, for a generic RelayCommand (with parameter).
private RelayCommand<string> _testAgainCommand; /// <summary> /// Gets the TestAgainCommand. /// </summary> public RelayCommand<string> TestAgainCommand { get { return _testAgainCommand ?? (_testAgainCommand = new RelayCommand<string>( p => { // Execute delegate throw new NotImplementedException(); }, p => { // CanExecute delegate throw new NotImplementedException(); })); } }
Do you find this way of creating the RelayCommands convenient? This limits the number of key press to a minimum (the only parameters to enter are the attribute name, the command’s name and (in the case of the generic RelayCommand) the type of the parameter. Looking for feedback before I consolidate this for V4!
Happy coding!
Laurent
Original Post: Proposing a new RelayCommand snippet for MVVM Light V4
The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.