InterviewSolution
| 1. |
What Is Use Of Icommand In Uwp? |
|
Answer» Typically, when you write an application without using the MVVM pattern, to manage the user’s interaction with the user interface (for example, he clicks on a button) you subscribe to a event handler: this way, a new method will be generated in code (C#) behind, which will contain the code that will be execute when the event is raised. This APPROACH is that it creates a strong connection between the View and the code: event handlers can be managed only in code behind, but you can’t simply move it to a ViewModel. The solution is to use commands, which are SPECIAL objects (that implement the ICommand interface) that define the operation to perform when the command is EXECUTED. Note: The Windows Runtime offers only the basic interface to support commands, which is ICommand: a developer, typically, would have to create its own CLASS to implement this interface. HOWEVER, all the MVVM frameworks usually offer it and Prism makes no exception: in this case, the class is called DelegateCommand. Typically, when you write an application without using the MVVM pattern, to manage the user’s interaction with the user interface (for example, he clicks on a button) you subscribe to a event handler: this way, a new method will be generated in code (C#) behind, which will contain the code that will be execute when the event is raised. This approach is that it creates a strong connection between the View and the code: event handlers can be managed only in code behind, but you can’t simply move it to a ViewModel. The solution is to use commands, which are special objects (that implement the ICommand interface) that define the operation to perform when the command is executed. Note: The Windows Runtime offers only the basic interface to support commands, which is ICommand: a developer, typically, would have to create its own class to implement this interface. However, all the MVVM frameworks usually offer it and Prism makes no exception: in this case, the class is called DelegateCommand. |
|