[]
Command binding allows InputPanel controls to execute application logic through the ICommand interface instead of direct UI event handlers.
This approach separates UI interaction from application logic and supports command-driven application architectures such as MVVM. Using commands instead of control-specific event handlers improves maintainability, simplifies testing, centralizes command execution logic, and allows the same command implementation to be reused across multiple controls.
InputPanel controls can invoke commands automatically in response to user interaction events such as button clicks, value changes, or text updates.
Supported Properties
Supported InputPanel controls expose the following command-related properties.
Property | Description |
|---|---|
| Specifies the |
| Optional value passed to the command during execution |
Command
The Command property binds the control to an ICommand implementation. The command executes automatically when the associated control interaction occurs.
CommandParameter
CommandParameter allows applications to pass contextual information to the command during execution. This is commonly used to identify the source control, provide operation context, pass metadata, or reuse a shared command across multiple controls.
Each supported InputPanel control invokes its bound command through a specific interaction event.
Control | Trigger Event | Behavior |
|---|---|---|
| Executes when the button is clicked | |
| Executes when the checked state changes | |
| Executes after the drop-down closes | |
| Executes after the date picker closes | |
| Executes when a hyperlink is clicked | |
| Executes when the text changes | |
| Executes after the menu closes | |
| Executes when the value changes | |
| Executes when the selected state changes | |
| Executes after the split-button menu closes | |
| Executes when the text changes | |
| Executes when the selected time changes | |
| Executes when the slider value changes |
InputPanel ControlThe following example demonstrates how to bind a command to an InputCheckBox.
Prerequisites
Include the required namespaces.
using System;using System.Windows.Forms;
using System.Windows.Input;Create a class that implements ICommand.
public class TestCommand : ICommand
{
public bool CanExecuteValue { get; set; } = true;
public bool WasExecuted { get; private set; } = false;
public object PassedParameter { get; private set; } = null;
public bool CanExecute(object parameter)
{
PassedParameter = parameter;
return CanExecuteValue;
}
public void Execute(object parameter)
{
PassedParameter = parameter;
WasExecuted = true;
MessageBox.Show("Command executed: " + parameter.ToString());
}
public event EventHandler CanExecuteChanged;
public void RaiseCanExecuteChanged() =>
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}The command implementation uses CanExecute to determine command availability, Execute to perform the command logic, and CanExecuteChanged to notify the UI when command availability changes.
Create an instance of the command.
private readonly TestCommand _command = new TestCommand
{
CanExecuteValue = true
};Assign the command and optional parameter to the control.
inputCheckBox.Command = _command;
inputCheckBox.CommandParameter = "CheckBox Toggled";When the checkbox state changes:
CanExecute is evaluated.
If CanExecute returns true, the command executes.
The control automatically updates its Enabled state.
InputPanel controls automatically synchronize their Enabled state using the result of the command CanExecute method.
Example:
public bool CanExecute(object parameter)
{
return false;
}When CanExecute returns false, the control becomes disabled and command execution does not occur.
This behavior allows command logic to control UI availability without requiring manual state updates.
Limitation | Description |
|---|---|
Enabled-state synchronization only | Only the |
No automatic visual-state management | Custom styling and visual-state changes are not managed automatically |
Frequent execution for some controls | Text and slider controls may trigger commands repeatedly |
Link metadata handling |
|