# Command Binding

## Content

Command binding provides a clean and flexible method for connecting user interface (UI) actions (such as button clicks or menu selections) to the underlying application logic that performs those actions. By binding a control (such as a C1Button) to a command object, developers can encapsulate the action, leading to improved maintainability, simplified testing, and strict adherence to the **Model-View-ViewModel (MVVM)** design pattern.

### **Key Features**

**<span class="cf0">Command Property:</span>** <span class="cf1">Accepts an ICommand object. The Execute() method is called automatically when the control is triggered. The control’s enabled state reflects the result of the command’s CanExecute() method to maintain UI and logic consistency.</span>

**<span class="cf0">CommandParameter Property:</span>** <span class="cf1">Passes optional data to the command to enable flexible and context-specific execution.</span>

**<span class="cf0">UI-to-Logic Binding:</span>** <span class="cf1">Connects any C1 control to a command that defines its behavior, allowing you to decouple UI actions from business logic.</span>

**<span class="cf0">Automatic Enable and Disable:</span>** <span class="cf1">Automatically updates the control’s enabled state based on the command’s availability (CanExecute()).</span>

**<span class="cf0">Separation of Concerns:</span>** <span class="cf1">Keeps execution logic in the ViewModel or controller, resulting in a cleaner and more maintainable UI layer.</span>

**<span class="cf0">Reusable and Testable Commands:</span>** <span class="cf1">Allows reuse of commands across multiple controls to improve consistency, reduce duplication, and make commands easier to unit test.</span>

**<span class="cf0">Undo and Redo Support:</span>** <span class="cf1">Provides a foundation for extending commands with undo and redo functionality when needed.</span>