Skip to content

Commit

Permalink
Describe the new multiple bindings syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
praeclarum committed Apr 30, 2014
1 parent d7bdc43 commit fe5677f
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ Bindings are symmetric, so you could just as well have written:
Then only difference occurs at initialization: the `stateEdit.Text` value is assigned to the `person.Address.State` value instead of the other way around.


#### Unbinding

`Binding.Create` returns a `Binding` object with one member `Unbind`. Calling this method permanently removes the bindings. If you want them back, you will need to re-create them.

var binding = Binding.Create (() => stateEdit.Text == person.Address.State);

...

binding.Unbind ();


#### Multiple Bindings

You can create multiple bindings by chaining them together with the and operator `&&`:

Binding.Create (() =>
nameEdit.Text == person.Name &&
stateEdit.Text == person.Address.State);

This is useful if you want to unbind a lot of data bindings all at once:

var multipleBindings = Binding.Create (() =>
nameEdit.Text == person.Name &&
stateEdit.Text == person.Address.State);

...

multipleBindings.Unbind ();


#### Complex Equality Binding

Sometimes you will want to bind a transformation or composition of data.
Expand All @@ -75,10 +105,11 @@ Consider the case of displaying a person's full name and allowing them to enter

public override void ViewDidLoad ()
{
Binding.Create (() => firstNameEdit.Text == person.FirstName);
Binding.Create (() => lastNameEdit.Text == person.LastName);
Binding.Create (() => fullNameLabel.Text == person.LastName + ", " + person.FirstName);
Binding.Create (() => Title == person.LastName + ", " + person.FirstName);
Binding.Create (() =>
firstNameEdit.Text == person.FirstName &&
lastNameEdit.Text == person.LastName &&
fullNameLabel.Text == person.LastName + ", " + person.FirstName &&
Title == person.LastName + ", " + person.FirstName);
}
}

Expand Down Expand Up @@ -113,11 +144,6 @@ will be automatically change tracked.



#### Unbinding

Call `Unbind` on the object returned from `Binding.Create` to cancel the binding.



## Error Handling

Expand Down

0 comments on commit fe5677f

Please sign in to comment.