[]
        
(Showing Draft Content)

Command Binding

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

Command

Specifies the ICommand instance executed when the control trigger event occurs

CommandParameter

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.


Supported Controls and Trigger Events

Each supported InputPanel control invokes its bound command through a specific interaction event.

Control

Trigger Event

Behavior

InputButton

OnClick

Executes when the button is clicked

InputCheckBox

OnCheckedChanged

Executes when the checked state changes

InputComboBox

OnDropDownClosed

Executes after the drop-down closes

InputDatePicker

OnDropDownClosed

Executes after the date picker closes

InputHtmlLabel

LinkClicked

Executes when a hyperlink is clicked

InputMaskedTextBox

OnTextChanged

Executes when the text changes

InputMenu

OnDropDownClosed

Executes after the menu closes

InputNumericBox

OnValueChanged

Executes when the value changes

InputRadioButton

OnCheckedChanged

Executes when the selected state changes

InputSplitButton

OnDropDownClosed

Executes after the split-button menu closes

InputTextBox

OnTextChanged

Executes when the text changes

InputTimePicker

OnValueChanged

Executes when the selected time changes

InputTrackBar

OnValueChanged

Executes when the slider value changes


Bind a Command to an InputPanel Control

The 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;

Step 1: Create a Command

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.

Step 2: Create and Initialize the Command

Create an instance of the command.

private readonly TestCommand _command = new TestCommand
{
    CanExecuteValue = true
};

Step 3: Bind the Command

Assign the command and optional parameter to the control.

inputCheckBox.Command = _command;
inputCheckBox.CommandParameter = "CheckBox Toggled";

Step 4: Run the Application

When the checkbox state changes:

  • CanExecute is evaluated.

  • If CanExecute returns true, the command executes.

  • The control automatically updates its Enabled state.


Automatic Enabled State Management

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.


Limitations

Limitation

Description

Enabled-state synchronization only

Only the Enabled property is updated automatically

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

InputHtmlLabel does not automatically pass the clicked URL as the command parameter