From e60900f55f5bb3e2534844d01cd6baaad6860e0a Mon Sep 17 00:00:00 2001 From: Stefan Glienke Date: Mon, 15 Jun 2015 18:36:07 +0200 Subject: [PATCH] added checkbox binding --- SimpleMVVM.Binding.Components.pas | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/SimpleMVVM.Binding.Components.pas b/SimpleMVVM.Binding.Components.pas index ce9c3ad..478ae4f 100644 --- a/SimpleMVVM.Binding.Components.pas +++ b/SimpleMVVM.Binding.Components.pas @@ -80,6 +80,13 @@ TLabelBinding = class(TBinding) function InitGetValue(const observable: IObservable): TFunc; override; end; + TCheckBoxBinding = class(TBinding) + protected + procedure HandleClick(Sender: TObject); + function InitGetValue(const observable: IObservable): TFunc; override; + procedure InitTarget; override; + end; + function GetBindingClass(const target: TObject; const expression: string): TBindingClass; implementation @@ -98,6 +105,8 @@ function GetBindingClass(const target: TObject; const expression: string): TBind Result := TLabelBinding else if (target is TButton) and SameText(expression, 'Click') then Result := TButtonBinding + else if (target is TCheckBox) and SameText(expression, 'Checked') then + Result := TCheckBoxBinding else Result := nil; end; @@ -323,4 +332,29 @@ function TLabelBinding.InitGetValue(const observable: IObservable): TFunc; +begin + Result := + function: TValue + begin + Target.Checked := observable.Value.AsBoolean; + end; +end; + +{$ENDREGION} + + end.