diff --git a/fx/README.md b/fx/README.md
index 100f6dc..7fb191f 100644
--- a/fx/README.md
+++ b/fx/README.md
@@ -171,7 +171,7 @@ A direct binding names a control by `fx:id`, a JavaFX property of that control,
For `both` and `model`, the write happens when the JavaFX property changes, including each change of a text property. There is no separate save. `view` does not write the attribute.
-`BindingList` is the element that holds direct bindings, computed bindings, and repeats. Its default property is `elements`, so the children in FXML are the list. An unknown child fails the load with `Not a binding element:`. The children that apply are a direct binding, a computed binding, and a repeat.
+`BindingList` is the element that holds direct bindings, computed bindings, command bindings, and repeats. Its default property is `elements`, so the children in FXML are the list. An unknown child fails the load with `Not a binding element:`. Command bindings require a managed View.
When the attribute value is already an `ObservableList`, the control property is set to that same list. Direction and converter are not consulted. The tag binding names `direction="view"` and still shares the list. See [A list of simple values](#a-list-of-simple-values).
@@ -266,6 +266,38 @@ A missing method fails the load with `No computed method "` and the method value
An `onAction="#method"` handler is ordinary FXML. `addVisit`, `addTag`, `leaveNote`, `leaveWarning`, and `leaveFatal` are handlers. They are separate from the computed binding.
+## Commands
+
+A `Command` combines an availability observable and an action. The ViewModel returns one
+stable instance from a public getter. A keyboard shortcut can call `execute()` directly.
+The command checks the current availability on every invocation.
+
+```java
+private final Command clear = new Command(documentOpen, editor::clear);
+
+public Command getClear() {
+ return clear;
+}
+
+void clearFromKeyboard() {
+ clear.execute();
+}
+```
+
+Load the FXML with a `ViewModelContext`. Inside its `BindingList`, add one declaration per
+button or menu item. Here both controls use the same `getClear()` command.
+
+```xml
+
+
+```
+
+Import `de.neitzel.fx.view.CommandBinding` and give both controls the corresponding `fx:id`.
+The binding owns the control's `disable` and `onAction` properties. Use the command's
+availability as the condition for disabling these controls. The managed View detaches
+both bindings on close. For dynamically created menu items, keep the registration from
+`CommandBindings.bind(item, command)` and close it when discarding the item.
+
## Controller
Name the class on the root with `fx:controller`. The container creates it with `getComponent`, so it is the cached singleton. `@FXML` fields are filled during load, before the bindings run.
diff --git a/fx/src/main/java/de/neitzel/fx/view/BindingList.java b/fx/src/main/java/de/neitzel/fx/view/BindingList.java
index 51987a4..daf1e8d 100644
--- a/fx/src/main/java/de/neitzel/fx/view/BindingList.java
+++ b/fx/src/main/java/de/neitzel/fx/view/BindingList.java
@@ -13,7 +13,7 @@ import java.util.Map;
* The list of binding elements declared inside {@code fx:define}.
*
* The list is not a scene-graph child. FXML adds each {@link DirectBinding},
- * {@link ComputedBinding}, or {@link Repeat} child to {@link #getElements()}.
+ * {@link ComputedBinding}, {@link CommandBinding}, or {@link Repeat} child to {@link #getElements()}.
*/
@DefaultProperty("elements")
public class BindingList {
@@ -48,6 +48,8 @@ public class BindingList {
DirectBindingApplier.apply(namespace, viewModel, directBinding, context, lifetime);
} else if (element instanceof ComputedBinding computedBinding) {
ComputedBindingApplier.apply(namespace, viewModel, controller, root, computedBinding, lifetime);
+ } else if (element instanceof CommandBinding commandBinding) {
+ CommandBindingApplier.apply(namespace, viewModel, commandBinding, lifetime);
} else if (element instanceof Repeat repeat) {
RepeatApplier.apply(namespace, viewModel, repeat, context, lifetime);
} else {
diff --git a/fx/src/main/java/de/neitzel/fx/view/Command.java b/fx/src/main/java/de/neitzel/fx/view/Command.java
new file mode 100644
index 0000000..b3bf73d
--- /dev/null
+++ b/fx/src/main/java/de/neitzel/fx/view/Command.java
@@ -0,0 +1,39 @@
+package de.neitzel.fx.view;
+
+import java.util.Objects;
+import javafx.beans.value.ObservableBooleanValue;
+import lombok.Getter;
+
+/**
+ * One action with a live availability rule. Use the command and its availability on the
+ * JavaFX application thread.
+ */
+public final class Command {
+
+ /** The availability observed by each control displaying this command. */
+ @Getter
+ private final ObservableBooleanValue canExecute;
+
+ private final Runnable action;
+
+ /**
+ * Creates a command for one action and execution context.
+ *
+ * @param canExecute live availability of the action
+ * @param action the work to start while the command is available
+ */
+ public Command(ObservableBooleanValue canExecute, Runnable action) {
+ this.canExecute = Objects.requireNonNull(canExecute);
+ this.action = Objects.requireNonNull(action);
+ }
+
+ /**
+ * Executes the action after checking the current availability, including for keyboard
+ * shortcuts or callers without an attached control.
+ */
+ public void execute() {
+ if (canExecute.get()) {
+ action.run();
+ }
+ }
+}
diff --git a/fx/src/main/java/de/neitzel/fx/view/CommandBinding.java b/fx/src/main/java/de/neitzel/fx/view/CommandBinding.java
new file mode 100644
index 0000000..959f69a
--- /dev/null
+++ b/fx/src/main/java/de/neitzel/fx/view/CommandBinding.java
@@ -0,0 +1,16 @@
+package de.neitzel.fx.view;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/** Connects an FXML button or menu item to a command supplied by its ViewModel. */
+@Getter
+@Setter
+public final class CommandBinding {
+
+ /** The target control's {@code fx:id}. */
+ private String control;
+
+ /** The simple bean property name of the command on the ViewModel. */
+ private String path;
+}
diff --git a/fx/src/main/java/de/neitzel/fx/view/CommandBindingApplier.java b/fx/src/main/java/de/neitzel/fx/view/CommandBindingApplier.java
new file mode 100644
index 0000000..7e82347
--- /dev/null
+++ b/fx/src/main/java/de/neitzel/fx/view/CommandBindingApplier.java
@@ -0,0 +1,102 @@
+package de.neitzel.fx.view;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.control.ButtonBase;
+import javafx.scene.control.MenuItem;
+
+final class CommandBindingApplier {
+
+ private CommandBindingApplier() {
+ }
+
+ static void validate(List lists, Map namespace) {
+ var commands = new IdentityHashMap