diff --git a/Runtime/Binding/CommandBinding.cs b/Runtime/Binding/CommandBinding.cs index a3ae65b..82ff5dd 100644 --- a/Runtime/Binding/CommandBinding.cs +++ b/Runtime/Binding/CommandBinding.cs @@ -46,12 +46,21 @@ public CommandBinding(VisualElement element, object boundObject, string key) } - element.RegisterCallback(OnClick); + if (element is Button button) + { + button.clicked += OnClick; + } + else + { + element.RegisterCallback(OnClick); + } + Command.CanExecuteChanged += SetCanExecute; SetCanExecute(null, null); } + private static object ParseArgument(string key) { if (bool.TryParse(key, out var boolResult)) return boolResult; @@ -60,7 +69,8 @@ private static object ParseArgument(string key) return key; } - private void OnClick(ClickEvent evt) => Command.Execute(_argument); + private void OnClick() => Command.Execute(_argument); + private void OnClick(ClickEvent evt) => OnClick(); private void SetCanExecute(object sender, EventArgs eventArgs) { @@ -71,7 +81,14 @@ private void SetCanExecute(object sender, EventArgs eventArgs) public void Unbind() { Command.CanExecuteChanged -= SetCanExecute; - Element.UnregisterCallback(OnClick); + if (Element is Button button) + { + button.clicked -= OnClick; + } + else + { + Element.UnregisterCallback(OnClick); + } } } } \ No newline at end of file